The operating principle SpringMVC

SpringMVC process

1, the user sends a request to the front-end controller DispatcherServlet.

2, DispatcherServlet HandlerMapping call processor receives a request mapper.

3, the processor mappers find specific processor (depending on the configuration xml, notes to find), the object is generated processors and processor interceptors (if there is generated) together return to DispatcherServlet.

4, DispatcherServlet call HandlerAdapter processor adapter.

5, HandlerAdapter through specific adaptation call processor (Controller, also known as back-end).

6, Controller execute complete return ModelAndView.

7, HandlerAdapter the controller ModelAndView the results back to the DispatcherServlet.

8, DispatcherServlet ModelAndView will pass ViewReslover view resolver.

9, ViewReslover returns parsed particular View.

10, DispatcherServlet render view (model data coming filled view) The View.

11, DispatcherServlet user response.

Component Description:

The following components are typically implemented using the framework provided:

DispatcherServlet: a front-end controller, the control center of the entire process, other components of the control, unified, reducing the coupling between components, improve the scalability of each component.

The HandlerMapping: ways to achieve different mapping by mapping extension processor, for example: profiles, to achieve interface mode, annotation methods. 

HandlAdapter: by extending processor adapter to support more types of processors.

ViewResolver: extended view by the parser, support more types of view resolution, for example: jsp, freemarker, pdf, excel like.

Components:
1, the DispatcherServlet front-end controller (not require engineers to develop), provided by the frame
effect: receiving a request, a response result, corresponding to the repeater, the central processor. With dispatcherServlet reduces the coupling between the other components.
A user request arrives at the front end of the controller, it is equivalent mvc mode c, dispatcherServlet center of the entire process is controlled by the other components of the processing which calls the user's request, the presence DispatcherServlet reduces coupling between components.

2, the processor HandlerMapping mapper (not require engineers to develop), provided by the frame
effect: The Handler lookup request url
HandlerMapping i.e. Handler responsible for finding processor upon user request, provides SpringMVC mapper different ways to achieve different mapping, e.g. : profiles, to achieve interface mode, annotation methods.

3, the adapter processor HandlerAdapter
effect: according to a specific rule (rule HandlerAdapter required) to perform Handler
for execution by the processor HandlerAdapter, which is an application of the adapter mode, the processor may be more types of expansion performed by the adapter.

4, processor Handler (required engineers to develop)
Note: do HandlerAdapter accordance with the requirements of the preparation Handler, so that the adapter can go to the correct execution Handler
Handler is the second back-end DispatcherServlet front controller, under the control of the DispatcherServlet Handler specific user requests are processed.
Since Handler related to specific user service request, it generally requires engineers to develop Handler according to business needs.

5 viewresolver View Resolver (not require engineers to develop), provided by the frame
effect: parsing a view, according to the logical view name resolves to a real view (View)
View is responsible for processing the Resolver View to generate the results, according to the first logic View the Resolver view name to a physical view of a particular name is the address of the page, then the view object generates view, view finally render the processing result to the user through display pages. springmvc View framework provides many types of views, comprising: jstlView, freemarkerView, pdfView like.
You need to model data show generally by page or tag page by page template technology to users, engineers need to develop a specific page based on business needs.

6, view View (required engineers to develop ... JSP)
View is an interface, implementation class support different types of View (jsp, freemarker, pdf ...)

Core architecture specific process steps are as follows:
1, the first user sends a request -> after DispatcherServlet, the front controller receives a request that they are not treated, but the commission process to other parsers, as a unified access point, the globally process control;
2, the DispatcherServlet -> the HandlerMapping, the request will be mapped to the HandlerMapping HandlerExecutionChain object (Handler comprising a processor (page controller) object, a plurality of interceptors HandlerInterceptor) object, such a strategy mode, it is easy to add the new mapping strategies;
3, the DispatcherServlet -> HandlerAdapter, HandlerAdapter will the processor packaging for the adapter to support multiple types of processors, namely the application of design patterns adapter, making it easy to support many types of processors;
4 , HandlerAdapter -> function call processing method of a processor, will be called HandlerAdapter is adapted according to the result of the real functionality of the processor processing method, the processing completion; ModelAndView object and returns a (comprising model data, logic View name);
. 5, a logical view ModelAndView name -> ViewResolver, ViewResolver name will resolve to a particular logical view View, this strategy mode, it is easy to replace other view technologies;
. 6, View -> Render, View will be passed in accordance with the model data to render model, model Map here is actually a data structure, it is easy to support the other view technologies;
7, returns control to the DispatcherServlet, DispatcherServlet response returned by the user, this flow ends a .

We need to develop under normal circumstances the following two components:

Handler: a processor that is represented by the back-end controller.

View: view, i.e., displayed to the user interface, typically a label view showing language model data.

 

In the prior SpringMVC let's look at what is MVC pattern

MVC: MVC is a design pattern

analysis:

Model M-Model (complete business logic: YES javaBean configuration, service + dao + entity)

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

C-Controller The controller (reception request -> call model -> distributed according to the result page)

 

What springMVC is: 

  springMVC is an open-source MVC framework, springMVC = struts2 + spring, springMVC plus the equivalent of Struts2 integration sring, but there is a doubt that, springMVC and spring is what to do with it? This has a good explanation on Baidu Encyclopedia: mean, springMVC spring is a follow-up product, in fact, spring based on the original, but also provides a MVC web application module can be simply understood as the springMVC spring one module (similar to AOP, this module IOC), the network often say springMVC seamless integration and spring, spring is in fact springMVC of a sub-module, so there is no need to integrate with the spring.

SpringMVC schematics:

See the map you may have a lot of doubts, and now we look at this map :( step can be understood in comparison MVC schematic)

The first step: the user initiates a request to the front end controller (the DispatcherServlet)

Step Two: front-end controller processor request mapper (HandlerMappering) to find the processor (the Handle): xml configuration or annotation by lookup

The third step: After finding processor mapper (HandlerMappering) as the front controller returns execution chain (HandlerExecutionChain)

Step Four: front-end controller (the DispatcherServlet) call handler adapter (HandlerAdapter is) to perform a processor (Handler)

Step five: processor adapter to perform Handler

Step Six: Handler executing the processor adapter to return ModelAndView

Seventh Step: a processor adapter returns to the front controller ModelAndView

Eighth step: a front end view resolver request controller (ViewResolver) to carry out the view resolution

Step 9: Back view resolver as front controller View

Step 10: a front end view of the controller for rendering

Tenth step: the response result to the user front-end controller

See these steps I believe we are feeling very chaotic, this is normal, but wants everyone to understand here is mainly springMVC of several components:

Front-end controller (DispatcherServlet): receiving a request, a response result, equivalent of a computer CPU.

Processor mapper (HandlerMapping): According to URL to find Processor

Processor (Handler) :( require programmers to write code processing logic)

Processor adapter (HandlerAdapter): The processor will be packaged into the adapter so that it can support multiple types of processors, analog (application adapters mode) notebook adapter

View resolver (ViewResovler): for view resolution, multi-string returned, the process can be resolved into the corresponding page

Original link: https://www.cnblogs.com/xiaoxi/p/6164383.html

Guess you like

Origin www.cnblogs.com/x-zhoulin/p/11527749.html