Compare the differences between STRUS2 and SPRING3 MVC:
- SPRING3 MVC is a method-level interception that, after intercepting the method, injects the request data into the parameter based on the annotations on the parameters, and in Spring3mvc, a method corresponds to a request context.
- The STRUTS2 framework is a class-level intercept, creating an action every time a request is made, and then invoking the setter getter method to inject the data from the request; Struts2 actually deals with the request through the setter getter method. ; in Struts2, an Action object corresponds to a request context.
All right, let's get this sorted out.
- Spring MVC is a method-level intercept, a method that corresponds to a request context, and a method that corresponds to a URL, so it is easy to implement a restful URL spring3 mvc from the schema itself.
STRUTS2 is class-level interception, a class corresponds to a request context, and implementing a restful URL is laborious because a method of struts2 action can correspond to a URL, and its class properties are shared by all methods. It is also not possible to identify the method that it belongs to by annotations or other means.
- The SPRING3 MVC approach is essentially independent of the request response data, requesting the data to be fetched through the parameters, and the results are returned by Modelmap to the framework method without sharing the variables
And the struts2, although the method is also independent, but all of its action variables are shared, this will not affect the program run, but to our code to read the program caused trouble.
- SPRING3 MVC validation is also a bright spot, support JSR303, processing AJAX Requests is more convenient to just one annotation @responsebody, and then directly return the response text.
Attach a section of code
View Plaincopy to Clipboardprint
- @RequestMapping (value= "/whitelists")
- Public String index (Modelmap map) {
- Account account = Accountmanager.getbydigitid (Securitycontextholder.get (). Getdigitid ());
- list<group> grouplist = Groupmanager.findallgroup (Account.getid ());
- Map.put ("account", account);
- Map.put ("Grouplist", grouplist);
- return "/group/group-index";
- }
- @ResponseBody Ajax Response
- @RequestMapping (value= "/whitelist/{whitelistid}/del")
- @ResponseBody
- Public String Delete (@PathVariable Integer whitelistid) {
- Whitelistmanager.deletewhitelist (Whitelistid);
- Return "Success";
- }
The difference between STRUS2 and spring3 MVC