Spring MVC 和 Struts MVC 的区别

发布于 2024-11-10 13:32:56 字数 1436 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

骄兵必败 2024-11-17 13:32:56

Spring MVC 和 Struts 之间的主要区别是:
Spring MVC 是松耦合框架,而 Struts 是紧耦合框架。对于企业应用程序,您需要构建松散耦合的应用程序,因为这将使您的应用程序更加可重用、健壮以及分布式。

The major difference between Spring MVC and Struts is:
Spring MVC is loosely coupled framework whereas Struts is tightly coupled. For enterprise Application you need to build your application as loosely coupled as it would make your application more reusable and robust as well as distributed.

清晨说晚安 2024-11-17 13:32:56

如果您想将 Spring MVC 与 Struts 进行比较,请考虑以下 Spring MVC 相对于 Struts 的优势。

  1. Spring 在控制器、JavaBean 模型和视图之间提供了非常清晰的划分。
  2. Spring的MVC非常灵活。与 Struts 不同,Struts 强制 Action 和 Form 对象进行具体继承(从而消除了 Java 中具体继承的单一机会),Spring MVC 完全基于接口。此外,Spring MVC 框架的几乎每个部分都可以通过插入您自己的接口进行配置。当然,我们还提供便利类作为实现选项。
  3. Spring 与 WebWork 一样,提供拦截器和控制器,从而可以轻松分解处理许多请求时常见的行为。
  4. Spring MVC 确实与视图无关。如果您不愿意,也不会被迫使用 JSP;您可以使用 Velocity、XLST 或其他视图技术。如果您想使用自定义视图机制 - 例如您自己的模板语言 - 您可以轻松实现 Spring View 接口来集成它。
  5. Spring 控制器像任何其他对象一样通过 IoC 配置。这使得它们易于测试,并与 Spring 管理的其他对象完美集成。
  6. Spring MVC Web 层通常比 Struts Web 层更容易测试,因为它避免了强制具体继承以及控制器对调度程序 servlet 的显式依赖。
  7. Web 层成为业务对象层之上的薄层。这鼓励良好的实践。 Struts 和其他专用 Web 框架让您自行实现业务对象; Spring 为应用程序的所有层提供了一个集成框架

If you wanna compare Spring MVC with struts consider below benefit of Spring MVC over Struts.

  1. Spring provides a very clean division between controllers, JavaBean models, and views.
  2. Spring's MVC is very flexible. Unlike Struts, which forces your Action and Form objects into concrete inheritance (thus taking away your single shot at concrete inheritance in Java), Spring MVC is entirely based on interfaces. Furthermore, just about every part of the Spring MVC framework is configurable via plugging in your own interface. Of course we also provide convenience classes as an implementation option.
  3. Spring, like WebWork, provides interceptors as well as controllers, making it easy to factor out behavior common to the handling of many requests.
  4. Spring MVC is truly view-agnostic. You don't get pushed to use JSP if you don't want to; you can use Velocity, XLST or other view technologies. If you want to use a custom view mechanism - for example, your own templating language - you can easily implement the Spring View interface to integrate it.
  5. Spring Controllers are configured via IoC like any other objects. This makes them easy to test, and beautifully integrated with other objects managed by Spring.
  6. Spring MVC web tiers are typically easier to test than Struts web tiers, due to the avoidance of forced concrete inheritance and explicit dependence of controllers on the dispatcher servlet.
  7. The web tier becomes a thin layer on top of a business object layer. This encourages good practice. Struts and other dedicated web frameworks leave you on your own in implementing your business objects; Spring provides an integrated framework for all tiers of your application
烟花易冷人易散 2024-11-17 13:32:56

struts 和 struts 之间的主要区别Spring MVC 是关于面向方面编程(AOP)和面向方面编程(AOP)之间的区别。面向对象编程(OOP)。

Spring通过使用依赖注入使应用程序松散耦合。Spring框架的核心是IoC容器。

OOP 可以做 AOP 所做的一切,但方法不同。换句话说,AOP 通过提供另一种思考程序结构的方式来补充 OOP。

实际上,当您想要对许多文件应用相同的更改时。使用 Struts 为大量文件添加相同的代码应该会很费力。相反,Spring 在其他地方写入新的更改并注入到文件中。

AOP的一些相关术语是横切关注点、切面、依赖注入……

The main difference between struts & spring MVC is about the difference between Aspect Oriented Programming (AOP) & Object oriented programming (OOP).

Spring makes application loosely coupled by using Dependency Injection.The core of the Spring Framework is the IoC container.

OOP can do everything that AOP does but different approach. In other word, AOP complements OOP by providing another way of thinking about program structure.

Practically, when you want to apply same changes for many files. It should be exhausted work with Struts to add same code for tons of files. Instead Spring write new changes somewhere else and inject to the files.

Some related terminologies of AOP is cross-cutting concerns, Aspect, Dependency Injection...

野の 2024-11-17 13:32:56

Spring 的 Web MVC 框架是围绕 DispatcherServlet 设计的,DispatcherServlet 将请求分派给处理程序,具有可配置的处理程序映射、视图解析、区域设置和主题解析以及对上传文件的支持。默认处理程序是一个非常简单的 Controller 接口,仅提供 ModelAndView handleRequest(request,response) 方法。这已经可以用于应用程序控制器,但您会更喜欢包含的实现层次结构,例如由 AbstractController、AbstractCommandController 和 SimpleFormController 组成。应用程序控制器通常是这些控制器的子类。请注意,您可以选择适当的基类:如果您没有表单,则不需要表单控制器。这是与 Struts 的一个主要区别

Spring's Web MVC framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for upload files. The default handler is a very simple Controller interface, just offering a ModelAndView handleRequest(request,response) method. This can already be used for application controllers, but you will prefer the included implementation hierarchy, consisting of, for example AbstractController, AbstractCommandController and SimpleFormController. Application controllers will typically be subclasses of those. Note that you can choose an appropriate base class: if you don't have a form, you don't need a form controller. This is a major difference to Struts

情绪少女 2024-11-17 13:32:56

Spring MVC 与 Spring 深度集成,而 Struts MVC 则不然。

Spring MVC is deeply integreated in Spring, Struts MVC is not.

影子的影子 2024-11-17 13:32:56

Spring 在控制器、JavaBean 模型和视图之间提供了非常清晰的划分。

Spring provides a very clean division between controllers, JavaBean models, and views.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文