The project has just changed the Web layer framework and abandoned struts2 instead of SPRING3MVC
When the framework was originally designed to compare simple---springmvc support rest, niche to restful URL heartily like
No need to know the use of the discovery of development efficiency is really higher than struts2
We used struts2 when using the traditional configuration file method, and did not use the legendary 0 configuration
SPRING3 MVC can be considered already 100% 0 configured (except for configuration Springmvc-servlet.xml)
Compare the differences between STRUS2 and SPRING3 MVC
============================================
The STRUTS2 framework is
class-level interception, each time a request is made, an action is created, and the setter getter method is called to inject the data in the request.
Struts2 is actually dealing with the request through setter getter methods.
In Struts2,
an Action object corresponds to a request context
Unlike Spring3 MVC, SPRING3MVC is a method-level intercept,
after intercepting the method according to the annotations on the parameters,
inject the request data in
In the SPRING3MVC,
a method corresponds to a request context
All right, let's get this sorted out.
Struts2 is a class-level interception, a class that corresponds to a request context,
Springmvc is a method-level interception, a method that corresponds to a request context, and a method that corresponds to a URL
So, from the architecture itself,
spring3 MVC is easy to implement restful URLs
And Struts2 's architecture is hard to implement.
because a method of struts2 action can correspond to a URL
And its class attributes are shared by all methods, which means they cannot be identified by annotations or other means.
===================================
Spring3mvc's approach is essentially independent, and the request response data is exclusive
Request data is obtained through parameters,
processing results are handed back to the framework via Modelmap
Do not share variables between methods
and Struts2, although the method is also independent, but all of its action variables are shared
This does not affect the program's operation, but it gives us trouble coding to read the program.
====================================
SPRING3 MVC validation is also a bright spot that supports JSR303
the request to process Ajax is more convenient just one annotation @responsebody, then directly return the response text can be
Attach a section of code
Java code@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";
- }
Comment Cut-off:
Annotations are not related to performance, and the servlet's life cycle is such that the servlet's class is created and the Init () method is run when the servlet is called. Then someone else runs the servlet without restarting the servlet and running the init () method inside, so the servlet container is simple interest, and spring is the framework of the servlet's encapsulation, Including all the dependency injections are all initialized when Tomcat is started, the other annotations are the same, that is, the annotation is the substitution of the previous XML configuration, no previous request to run the XML once? Not, XML is read at Tomcat startup and uses the configuration inside to initialize a lot of things, and then it is not used, because all become simple interest, so that the efficiency, not every time we have to inject all the new once, But when Tomcat starts, all new will not be new again, ensuring efficiency.
So I don't understand that the light look at the annotations to know the performance is not good?
Annotations Replace the XML configuration and are initialized once, meaning that there is a lot of work done in Init () like a servlet, and will not be running init () until you restart Tomcat.
Struts1, too, creates an action class when running a method of action, which is not created at a later time, but is also a framework for the servlet's encapsulation.
STRUTS2 special, not a request to new action to ensure thread safety. So the efficiency will be lower, but not low is particularly outrageous.
This also shows that spring3 MVC and struts1 MVC and servlet are thread-safe methods, so the private or public variables declared in the class method are not thread-safe, struts2 is indeed thread-safe.
All have their own advantages, with what is of course the benevolent see of the beholder.
But we do use spring3 in a lot of new projects because rest is good.
Comparison between SPRING3MVC and Struts2