Comparison of SpringMvc and Struts2, which is better

1. Core controller (front-end controller, preprocessing controller): This word should not be unfamiliar to those who have used the mvc framework. The main purpose of the core controller is to process all requests, and then to those special requests (Controller) unified processing (character encoding, file upload, parameter acceptance, exception handling, etc.), spring mvc core controller is Servlet, and Struts2 is Filter.
  Struts2 is a class-level interception, and a class corresponds to a request context.
  SpringMVC is a method-level interception, a method corresponds to a request context, and a method corresponds to a url at the same time, so from the architecture itself, SpringMVC can easily implement restful urls.
   The structure of struts2 is difficult to implement, because a method of Action in Struts2 can correspond to a url, but its class attributes are shared by all methods, so it is impossible to use annotations or other methods to identify the method to which it belongs.
2. Controller instance: Spring Mvc will be faster than Struts (in theory). Spring Mvc is based on method design, while Sturts is based on objects. Each time a request is made, an action will be instantiated, and each action will be injected with attributes. Spring is more like Servlet, with only one instance, and the corresponding method is executed for each request. Yes (note: since it is a singleton instance, the modification of global variables should be avoided, which will cause thread safety problems).
     For the above reasons, SpringMVC's methods are basically independent, and they share the request response data exclusively. The request data is obtained through parameters, and the processing results are returned to the framework through ModelMap. Variables are not shared between methods, and Struts2 is messy. Although the methods are also independent, all their Action variables are shared, which will not affect the running of the program, but it will bring trouble when we code and read the program. Every time a request comes, an Action is created, and an Action object corresponds to one request context.
3. Because Struts2 needs to encapsulate each request, encapsulate the variables of the servlet life cycle such as request and session into a Map, supply each Action, and ensure thread safety, so in principle, it is more memory-intensive.
4. In terms of interceptor implementation mechanism, Struts2 has its own interceptor mechanism, and SpringMVC uses an independent AOP method, which leads to the fact that the amount of configuration files of Struts2 is still larger than that of SpringMVC.
5. The entrance of SpringMVC is servlet, and Struts2 is filter, which leads to different mechanisms of the two.

6. Parameter passing: Struts2 itself provides a variety of parameters to accept, in fact, are passed and assigned through (ValueStack), and SpringMvc is received through the parameters of the method.

7. Learning difficulty: Struts has many new technical points, such as interceptors, value stacks and OGNL expressions. The learning cost is high. Springmvc is relatively simple and can be used in very little time.

8. SpringMVC integrates Ajax, which is very convenient to use. It can be implemented with only one annotation @ResponseBody, and then directly returns the response text. The Struts2 interceptor integrates Ajax. When processing in Action, you must install plug-ins or write your own code. Integrated into it, it is relatively inconvenient to use.

9. SpringMVC verification supports JSR303, which is relatively more flexible and convenient to handle, while Struts2 verification is cumbersome and feels too annoying.
10. Spring MVC and Spring are seamless. The management and security of this project is also higher than that of Struts2 (of course, Struts2 can also achieve the same effect as SpringMVC through different directory structures and related configurations, but there are many places that require xml configuration).
11. In terms of design ideas, Struts2 is more in line with OOP programming ideas, and SpringMVC is more cautious and extends on servlets.
12. Management method: Spring is used in the core architecture of most companies, and spring mvc is a module in spring, so spring is simpler and more convenient for spring mvc controller management, and provides a full annotation method For management, the annotations of various functions are relatively comprehensive and easy to use, while struts2 needs to use a lot of XML configuration parameters to manage (although annotations can also be used, but almost no companies use them). SpringMVC development efficiency and performance are higher than Struts2.
13. SpringMVC can be considered 100% zero configuration.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327033291&siteId=291194637