Spring MVC integrated Velocity template
Spring MVC
We used struts2 when using the traditional configuration file in a way that did not use the legendary 0 configuration. SPRING3 MVC can be thought of as having 100% 0 configured (in addition to configuring spring Mvc-servlet.xml).
The difference between Spring MVC and STRUTS2:
1. Mechanism: Spring MVC's entry is the servlet, and Struts2 is the filter (it is noted here that the filter and servlet are different.) Previously thought that filter was a special type of servlet, which led to a different mechanism between the two, which involved the difference between servlet and filter.
2. Performance: Spring will be slightly faster than struts. Spring MVC is a method-based design, and Sturts is class-based, each time a request is made with an action, each action is injected into the attribute, and spring is based on a method that is finer grained, but be careful to hold the same data as the servlet. SPRING3 MVC is a method-level interception that, after intercepting a method, injects the request data into a parameter based on annotations, and in Spring3 MVC, 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.
3. Parameter passing: Struts is a parameter that can be accepted with attributes when it is accepted, which means that the parameters are shared by multiple methods.
4. Design thinking: Struts more in line with OOP programming ideas, Spring is more cautious, extended on the servlet.
5. Intercepter implementation mechanism: Struts has its own interceptor mechanism, and spring MVC uses an independent AOP approach. This leads to the profile of struts is still larger than spring MVC, although the configuration of struts can inherit, so I think in terms of use, Spring MVC use more concise, development efficiency Spring MVC is really higher than struts2. 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. Spring3 MVC method is basically independent, the request response data, requests data through parameters, processing results through the MODELMAP to the framework method is not shared between the variables, and struts2 make is more chaotic, although the method is also independent, But all of its action variables are shared, which does not affect the program's operation, but it gives us code and trouble reading the program.
6. In addition, SPRING3 MVC validation is also a bright spot, support JSR303, processing AJAX Requests is more convenient, just a note @responsebody, and then directly return the response text.
Wait a minute...... The original text can not be found, to find a link in the past, this is not the focus of the introduction. Velocity Template
For Java programmers, the best template engines are no more than Velocity and Freemarker. But for a person who has not been in touch with these two projects, they do not know which one to choose and which is best for them. The following content comes from a more pertinent comparison on the Freemarker website, although it is more inclined to Freemarker:
Velocity is simpler and more lightweight than freemarker, but its function is not freemarker so powerful.
For most applications, using Freemarker is easier than velocity, because velocity also has to write some custom toolbox classes and write some more generic template code over and over and over and over again, thus losing more valuable time at the start of development. In addition, the use of tool classes and workarounds does not seem to be a very effective approach in the template engine. At the same time, Velocity's approach makes it much easier to interact with Java objects in the velocity template, which violates the simple principle, although you can also move the code into the controller implementation. Of course, if you use freemarker like velocity, then freemarker can be as simple as velocity.
Wait a minute......
Please see this is not the focus of the introduction.
Required Package files
Spring MVC only uses MVC so it only needs the 8 packages; Velocity uses 2 packets. Xml?
<servlet> <servlet-name>mvc3</servlet-name> & nbsp; <servlet-class > Org.springframework.web.servlet.DispatcherServlet </servlet-class > <init-param> <param-name> Contextconfiglocation</param-name> <param-value> web-inf/main-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc3</servlet-name> <url-pattern>/</ url-pattern> |