1.
What is SPRINGMVC?
Spring MVC is a lightweight web framework that implements the request-driven type of the Web MVC design pattern based on Java, that is, the idea of using the MVC architecture pattern, decoupling the web layer from responsibility, and based on the request-driven approach is to use the request-response model, The purpose of the framework is to help us simplify our development, and Spring MVC simplifies our daily web development. Spring MVC is also an implementation of service-to-worker mode, but is optimized. The front controller isDispatcherservlet; The application controller is actually split into a processor mapper (Handler Mapping) for management of the processor and view Resolver for the management of Views; Page Controller/action/ The processor is an implementation of the Controller interface (which contains only the Modelandview handlerequest (Request, response) method), which can also be any Pojo class, support localization (Locale) parsing, Topics (Theme) parsing and file uploading, etc. provide very flexible data validation, formatting, and data binding mechanisms, and provide a powerful contract-like programming support that is larger than the configuration (customary precedence principle).
Spring Web MVC and S-truts2 are both the framework of the presentation layer , which is part of the Spring framework , we can get from Spring The overall structure , such as:
2. What can SPRINGMVC do for us? √ allows us to design a clean web layer and a thin web layer very simple, √ a more concise web layer development, √ natural integration with the spring framework (such as IOC container, AOP, etc.), √ provide a strong convention than the configuration of contractual programming support; √ Simple unit testing of the Web layer √ Support Flexible URL-to-page mapping; √ integrates easily with other view technologies, such as velocity, freemarker, and so on, because model data is not placed in a particular API, but is placed in a model (map data structures are implemented and therefore easily used by other frameworks);√ Very flexible data validation, formatting and data binding mechanism, can use any object for data binding, do not need to implement a specific framework of api;√ provide a set of powerful JSP tag library, simplify JSP development; √ Support flexible localization, subject resolution; √ Simpler exception handling; √ Support for static resources ; √ Support restful style.
3.SpringMVC Processing Flow
As shown in the following:
Frame Structure of 4.SpringMVC
4.1.
Architecture Process
1, the user sends the request to the front controller Dispatcherservlet
2. Dispatcherservlet received a request to call the Handlermapping processor mapper.
3. The processor mapper locates the specific processor according to the request URL, and returns the Processor object and the processor interceptor (if any) to Dispatcherservlet.
4. Dispatcherservlet calls the processor via the Handleradapter processor adapter
5, the execution processor (Controller, also known as the back-end controller).
6, controller execution completed return Modelandview
7, Handleradapter the controller execution results Modelandview returned to Dispatcherservlet
8. Dispatcherservlet Pass Modelandview to Viewreslover view parser
9, Viewreslover after parsing return to the specific view
10. Dispatcherservlet view is rendered (the model data is populated into the view).
11. Dispatcherservlet Response User
4.2 Description of the components in the schema
The following components typically provide implementations using the framework:
Dispatcherservlet: Front Controller
The user request arrives at the front controller, it is equivalent to the MVC pattern C,dispatcherservlet is the entire Process Control center, by it calls other components processing user's request, the Dispatcherservlet existence reduced the coupling between the components.
handlermapping: Processor Mapper
Handlermapping is responsible for the user request URL to find handler is the processor, SPRINGMVC provides different mapper implementation of different mapping methods, such as: Configuration file mode, implementation interface, annotation method.
Handler: Processor
The Handler is the back-end controller of the Dispatcherservlet front-end controller, which is processed under the control of Dispatcherservlet Handler to specific user requests.
because Handler involves specific user business requests, so the general situation requires programmers to develop handler based on business requirements.
Handladapter: Processor Adapter
through The Handleradapter executes on the processor, which is an application of the adapter pattern that can be performed on more types of processors through the extension adapter.
are many different adapters that can eventually be connected using a USB interface
Viewresolver: View Resolver
View Resolver is responsible for generating a view view of the processing results, and the view Resolver first resolves to the physical view name that is the specific page address based on the logical view name, and then the view object is generated. The final rendering of the view renders the processing results to the user through the page.
View: Views
The SPRINGMVC framework provides support for many view view types, including: Jstlview, Freemarkerview, Pdfview, and so on. The most common view we use is JSP.
In general, the model data needs to be presented to the user through page labels or page template technology, and the programmer needs to develop specific pages based on the business requirements.
Description: In the various components of SPRINGMVC, the processor mapper, processor adapter, and view resolver are called the three components of the SPRINGMVC.
Components that require user development are handler,view
5.
Springmvc is different from struts2
1 . The SPRINGMVC entrance is a servlet , the front controller, and the struts2 entry is a filter Filter.
2, springmvc is based on method development one url corresponds to a method ) Request parameters are passed to the parameter of the method and can be designed as singleton or multiple ( suggested Singleton struts2
3, Struts uses the value stack to store the request and the response data, through the OGNL accesses the data, SPRINGMVC through the parameter parser is the request Request content parsing, and assign values to the method parameters, encapsulate the data and view as modelandview objects, and finally Pass the model data in the Modelandview the request domain is transferred to the page. the JSP View parser uses Jstl by default .
Statement: I have limited capacity, in the preparation of errors may be, you are welcome to point out.
Springmvc Getting Started