Spring MVC Architecture

Source: Internet
Author: User
Tags expression engine

"Spring MVC class Diagram"
"Spring Combat" in:
"Spring3.0 is so Simple" in:
"Http://blog.csdn.net/gstormspire/article/details/8239182"
==========================================================================

Spring MVC performs better in high concurrency and has very little intrusive code, and the lightweight reason makes development more efficient than Struts2.
Spring MVC is closer to the target of "0 configuration".

==========================================================================

The--MVC framework appears to map URLs from the world of HTTP to the Java world, which is the core function of the MVC framework. And at the URL this point Springmvc undoubtedly more elegant.
--From a design perspective, I think SPRINGMVC is clearer. Even if we were to compare Struts2 's schematic and Springmvc's class diagram, it's still confusing, far from SPRINGMVC more intuitive

SPRINGMVC design ideas: Standardize the entire process and assign each process step to a different component for processing.
This scenario actually involves two areas:
L Processing Process Normalization-divides the processing process into several steps (tasks) and concatenates all the steps using a clear logical main line
L Process component-defines each step (task) in the processing process as an interface and assigns different implementation patterns to each interface

The process normalization is the purpose, and the procedure and process definition of the process are the means. Thus, the primary content of process normalization is to consider the logical steps that a generic servlet responder should roughly include:
L step to the HTTP request for preliminary processing, find the corresponding Controller processing class (method)--handlermapping
L Step 2--Call the appropriate Controller processing class (method) to complete the business logic--handleradapter
L Step 3--Handle exceptions that can occur when a controller processes a class (method) Call--handlerexceptionresolver
L Step 4--HTTP Response processing based on the call result of the Controller processing class (method)--viewresolver

STRUTS2 Advantages:
STRUTS2 's ability to dominate the development market over a long period of time is due to its technological leadership. The leading edge of this technology is highlighted by a thorough transformation of the controller:
public class Usercontroller {
Private User User
Public String execute () {
Add business logic code here
Return "Success";
}
}
From the code above, we can see that Webwork2/struts2 has two points for the controller's biggest retrofit:
1. Completely eliminate the introduction of native servlet objects such as HttpServletRequest or HttpServletResponse in the controller.
2. The request parameters and response data are stripped from the response method to the property variables in the controller.

The entire controller class is completely decoupled from the Web container and can be easily tested in a unit.

Because the attribute variables in the off-limits controller in the traditional servlet pattern are reasonably utilized as part of the data in the request processing process. This transformation not only allows the expression engine to be maximized, but also makes the entire controller look more like a pojo. Thus, this form of expression is named by the Author: Pojo implementation mode. The Pojo implementation pattern is a revolutionary pattern because it is able to maximize the idea of decoupling. From an object-oriented perspective, the Pojo pattern is undoubtedly one of the goals that all programmers pursue. This is one of the important reasons why Webwork2/struts2 has been enduring for so many years.


So, the first reason we see this is that STRUTS2 relies on technological innovation to win the favor of programmers. But the Struts2 of technological innovation over the years seems to have taken a smaller stride. We can see that after the popularization of JDK1.5, annotation as a new Java syntax, is gradually known and applied. This point Springmvc followed the trend of the times, directly for the request-response mapping. But Struts2 has been unable to form a breakthrough in the single configuration source. Of course, this is just a simple example of technological innovation, and there are many other examples.
At least that's the way it feels to people. Struts is not very dipping at this point, as spring's word of mouth and influence also objectively deepens everyone's impression of SPIRNGMVC as a technology leader.

"Note" The current STRUTS2 also has its own annotations.

==========================================================================

Struts2 is a class-level interception, and a class 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 it's easy to implement restful URLs spring3 MVC from the architecture itself.
The STRUTS2 architecture is hard to implement because one method of struts2 action can correspond to a URL, and its class properties are shared by all methods, which means that it cannot be identified by annotations or other means.

Spring3mvc's approach is essentially independent, and the request response data is exclusive. The request data is obtained through the parameters, and the processing results are returned to the framework via MODELMAP. The variables are not shared 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.

The validation of Spring3 MVC 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.

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, each 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 Servlets are thread-safe methods, so private or public variables declared in class methods are not thread-safe. The struts2 is indeed thread-safe.

==========================================================================

The portal to 1.spring MVC is a servlet, and Struts2 is the filter
2. Performance: Spring will be slightly faster than struts. Spring MVC is a method-based design, and Sturts is class-based.
"Class-based: Refers to a URL request that corresponds to an action class to handle"
"Based on Method: A method in a request corresponding class is processed"
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.
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.

Spring MVC Architecture

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.