The difference between SpringMVC and Struts2

The difference between SpringMVC and Struts2 
1. Mechanism:

The entrance of spring mvc is servlet, and struts2 is filter, which leads to different mechanisms of the two.   

2. Performance:

Spring will be slightly faster than struts. Spring mvc is a method-based design, while sturts is class-based. Every time a request is made, an action will be instantiated, and each action will be injected with attributes, while spring is method-based and has a finer granularity, but be careful to control data like in servlet Same. Spring3 mvc is a method-level interception. After intercepting the method, the request data is injected into it according to the annotations on the parameters. In spring3 mvc, a method corresponds to a request context. The struts2 framework is a class-level interception. Every time a request comes, an Action is created, and then the setter getter method is called to inject the data in the request; struts2 actually deals with the request through the setter getter method; in struts2, an Action object Corresponds to a request context.   

3. Parameter passing:

When struts accepts parameters, it can use attributes to accept parameters, which means that parameters are shared by multiple methods.   


4. Design thinking:

Struts is more in line with the programming idea of ​​oop (object-oriented programming), and spring is more cautious and expands on servlet.

   
5. Implementation mechanism of intercepter:

Struts has its own interceptor mechanism, and spring mvc uses an independent AOP method. As a result, the amount of configuration files of struts is still larger than that of spring mvc, although the configuration of struts can be inherited, so I think that in terms of use, the use of spring mvc is more concise, and the development efficiency of spring mvc is indeed higher than that of struts2. Spring mvc is a method-level interception, a method corresponds to a request context, and a method corresponds to a url at the same time, so spring3 mvc can easily implement restful url from the architecture itself. Struts2 is a class-level interception, a class corresponds to a request context; it takes effort to implement a restful url, because a method of struts2 action can correspond to a url; and its class attributes are shared by all methods, which cannot use annotations or other methods. Identifies the method to which it belongs. The methods of spring3 mvc are basically independent, and the request response data is exclusively used. The request data is obtained through parameters, and the processing results are returned to the framework through ModelMap. Variables are not shared between methods, while struts2 is messy, although between methods It is also independent, but all its Action variables are shared, which will not affect the operation of the program, but it will bring trouble to us when coding and reading the program. 

  
6. In addition, the verification of spring3 mvc is also a highlight. It supports JSR303, and it is more convenient to process ajax requests. Just annotate @ResponseBody and return the response text directly.

recommended article:

Comparison of SpringMVC and Struts2

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325323793&siteId=291194637