The difference between STRUS2 and spring3 MVC

Source: Internet
Author: User

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.

    1. 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.
    2. 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.
    3. 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
    1. @RequestMapping (value= "/whitelists")
    2. Public String index (Modelmap map) {
    3. Account account = Accountmanager.getbydigitid (Securitycontextholder.get (). Getdigitid ());
    4. list<group> grouplist = Groupmanager.findallgroup (Account.getid ());
    5. Map.put ("account", account);
    6. Map.put ("Grouplist", grouplist);
    7. return "/group/group-index";
    8. }
    9. @ResponseBody Ajax Response
    10. @RequestMapping (value= "/whitelist/{whitelistid}/del")
    11. @ResponseBody
    12. Public String Delete (@PathVariable Integer whitelistid) {
    13. Whitelistmanager.deletewhitelist (Whitelistid);
    14. Return "Success";
    15. }

The difference between STRUS2 and spring3 MVC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.