Spring MVC schematic diagram

Source: Internet
Author: User
Tags map data structure

SPRINGMVC Working principle diagram:

SPRINGMVC 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 found a specific processor (can be based on XML configuration, annotations to find), the generation of processor objects and processor interceptors (if any) are returned to Dispatcherservlet.

4, Dispatcherservlet call Handleradapter processor adapter.

5, Handleradapter through the adaptation of the call to the specific 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 the Modelandview to Viewreslover view parser.

9, Viewreslover after parsing to return to the specific view.

10. Dispatcherservlet the rendered view based on the view (populate the model data into the view).

11, Dispatcherservlet response to users.

Component Description:

The following components typically provide implementations using the framework:

Dispatcherservlet: As the front controller, the entire Process Control center, control other components execution, unified scheduling, reduce the coupling between components, improve the extensibility of each component.

Handlermapping: Through the extension of the processor mapper to achieve different mapping methods, such as: Configuration file mode, the implementation of interface mode, annotation method and so on.

Handladapter: Supports more types of processors by extending the processor adapter.

Viewresolver: Supports more types of view resolution by extending the view parser, such as JSP, Freemarker, PDF, Excel, and more.

Component:
1. Front Controller Dispatcherservlet (no engineer development required), provided by the framework
Function: Receive request, response result, equivalent to transponder, CPU. With the Dispatcherservlet, the coupling between the other components is reduced.
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.

2. Processor Mapper Handlermapping (no engineer development required), provided by the framework
Function: Find handler based on the URL requested
Handlermapping is responsible for the user's request to find handler is the processor, SPRINGMVC provides different mapper implementation of different mapping methods, such as: Configuration file mode, interface mode, annotation and so on.

3. Processor Adapter Handleradapter
Function: Execute handler According to the specific rules (Handleradapter requirements)
The processor is executed through the Handleradapter, which is an application of the adapter pattern that can be performed on more types of processors through the extension adapter.

4, processor handler (need engineer development)
Note: When writing handler, follow Handleradapter's instructions so that the adapter can go to the correct execution handler
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.
Since handler involves specific user business requests, the general situation requires engineers to develop handler based on business requirements.

5. View Resolver views Resolver (no engineer development required), provided by the framework
Function: Perform a view resolution, resolve to a real view based on the logical View name (view)
View resolver is responsible for generating a view view of the processing results, the view resolver first resolves the logical view name to the physical view name that is the specific page address, then generates the View object, and finally renders the view to show the user the results of the processing. The SPRINGMVC framework provides a number of view view types, including: Jstlview, Freemarkerview, Pdfview, and so on.
In general, the model data needs to be presented to the user via page label or page template technology, and the specific page needs to be developed by the engineer according to the business requirements.

6. Views view (requires engineer to develop JSP ...)
View is an interface that implements classes that support different view types (JSP, Freemarker, pdf ...). )

The specific process steps for the core architecture are as follows:
1, the first user sends the request-->dispatcherservlet, the front controller receives the request not to carry on the processing, but entrusts to the other parser carries on the processing, as the unified access point, carries on the global flow control;
2, dispatcherservlet-->handlermapping, handlermapping will map the request to a Handlerexecutionchain object (containing a handler processor (page Controller) object, Multiple Handlerinterceptor Interceptors) object, through this strategy mode, it is easy to add a new mapping strategy;
3, Dispatcherservlet-->handleradapter,handleradapter will be the processor packaging as an adapter, thereby supporting a variety of types of processors, adapter design mode of application, so it is easy to support many types of processors;
4, handleradapter--> processor function processing method call, Handleradapter will be based on the results of the adaptation to call the real processor function processing method, complete the function processing, and return a Modelandview object (including model data, logical view name);
5, Modelandview logical View name----Viewresolver, Viewresolver will parse the logical view name into a specific view, through this strategy mode, it is easy to replace other view technology;
6, view--> rendering, the view will be based on the model data passed in to render, here the model is actually a map data structure, so it is easy to support other view technology;
7, return control to Dispatcherservlet, by Dispatcherservlet return response to the user, to this end of a process.

The following two components typically require development:

Handler: The processor, the back-end controller, is represented by controllers.

View: The interface that is presented to the user, which typically requires the tag language to present the model data.

Let's take a look at what the MVC pattern is before we get SPRINGMVC.

MVC:MVC is a design pattern

MVC schematic diagram:

Analysis:

M-model model (Complete business logic: JavaBean composition, service+dao+entity)

V-view view (do the display of the interface jsp,html ... )

C-controller Controller (receive request, call model, distribute pages based on results)

What is SPRINGMVC:

  SPRINGMVC is an open-source framework for MVC, SPRINGMVC=STRUTS2+SPRING,SPRINGMVC is equivalent to STRUTS2 plus sring integration, but here's a question that What is the relationship between SPRINGMVC and spring? This in Baidu Encyclopedia has a very good explanation: means that SPRINGMVC is a follow-up product spring, in fact, spring on the original basis, but also provides the Web application of the MVC module, SPRINGMVC can be simply understood as a spring module (similar to AOP,IOC), the network is often said SPRINGMVC and spring seamless integration, in fact, SPRINGMVC is a sub-module of spring, So there is no need to integrate with spring.

Schematic diagram of SPRINGMVC:

See this figure there may be a lot of confusion, now let's take a look at the steps of this diagram: (You can compare the MVC schematic to understand)

First step: The user initiates the request to the front controller (dispatcherservlet)

Step Two: Front Controller request processor Mapper (handlermappering) to find the processor (Handle): Find by XML configuration or annotations

Step three: Find the processor mapper (handlermappering) as the front controller returns to the execution chain (handlerexecutionchain)

Fourth step: The Front controller (Dispatcherservlet) calls the processor adapter (Handleradapter) to execute the processor (Handler)

Fifth Step: Processor adapter to perform handler

Sixth step: Handler execution to the processor adapter return Modelandview

Seventh Step: The processor adapter returns Modelandview to the front-end controller

Eighth step: The front controller requests the View parser (Viewresolver) to carry out the visual diagram analysis

Nineth Step: View resolver like Front controller return view

Tenth step: Front Controller renders view

11th Step: Front controller responds to user results

See these steps I believe everyone is very confused, this is normal, but here is mainly to understand the springmvc of several components:

Front-end Controller (dispatcherservlet): Receives the request, responding to the result, equivalent to the computer's CPU.

Processor Mapper (handlermapping): To find the processor based on the URL

Processor (Handler): (Requires programmer to write code processing logic)

Processor Adapter (Handleradapter): The processor will be packaged as an adapter, so that it can support multiple types of processors, Analog notebook adapter (adapter mode application)

View Resolver (Viewresovler): For view resolution, multiple returned strings, processed, can be parsed into corresponding pages

Reference Link: https://www.cnblogs.com/xiaoxi/p/6164383.html

Spring MVC schematic diagram

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.