Above is the schematic diagram of SPRINGMVC's work:
1. Client request submitted to Dispatcherservlet
2, Dipatcherservlet received this request will be based on the requested information, call Handlermapping to obtain the handler
3, Dispatcherservlet According to obtain the handler, chooses a suitable handleradapter.
4, Handleradapter will return a Modelandview () object to Dispatcherservlet after the data processing is complete.
5. Handleradapter returned Modelandview () is just a logical view that is not a formal view. Dispatchersevlet transforms a logical view into a true views view through Viewresolver.
6. The view will render the full view and return it to the client based on the model data that was passed in.
the detailed process process for the core architecture is as follows:1, the first userSend Request-->dispatcherservlet. the front controller does not process itself when the request is received. Instead, it is entrusted to other parsers.processing, as a unified access point, for global process control. 2.dispatcherservlet-->handlermapping,handlermapping will map the request to the Handlerexecutionchain object (including aHandler Processor (page Controller) object, multiple Handlerinterceptor interceptors) object, through such a policy mode, very easy to join the newmapping strategy;3.Dispatcherservlet-->handleradapter,The Handleradapter will wrap the processor as an adapter. This supports multiple types of processors. that is, the adapter design mode of application, so very easy to support a very many types of processors;4.handleradapter--> Processor Function processing method call, Handleradapter will invoke the function of the real processor based on the result of the adaptation.function processing, and returns a Modelandview object (including model data, logical view name);5.Modelandview Logical View name---Viewresolver, Viewresolver will parse the logical view name into a detailed view,mode. Very easy to replace other view technology;6.view--> Rendering, the view is rendered based on the model data passed in, where the model is actually a map data structure. Sovery easy to support other view technology;7.return control to Dispatcherservlet,The response is returned by Dispatcherservlet to the user, to the end of this process.
through the trauma .
now think about these questions.1, how to request the front controller? this should be inWeb. XMLDescribed in the deployment description. In theHelloWorldin the specific explanation. 2, the front controller how to select the page controller based on the request Information function processing? we need to configurehandlermappingto map3, how to support multiple page controllers? ConfigurationHandleradaptersupport for multiple types of page controllers4, how does the page controller use the business object? To anticipate, be sure to useSpring IoCthe container's dependency injection function5, how does the page controller return the model data? UseModelandviewreturn6, how does the front controller select a detailed view for rendering based on the logical view name returned by the page controller? UseViewresolverto parse7, how do different view technologies use the corresponding model data? becauseModelis aMapdata structure, very easy to support other view technology
Spring MVC Development Process
- Create a new Web project
- Join Spring Support
- Configure Web. XML to join configuration Dispatcherservlet
- Implementing the module Layer
- Implementing a Controller
- Implementing the View Layer *.jsp
- Change Applicationcontext.xml
Here we can see the detailed core development steps:1. Dispatcherservlet deployment descriptive narrative in Web. XML to intercept requests to spring Web MVC2. Handlermapping configuration, which maps the request to the processor3, the Handleradapter configuration. Support for multiple types of processors4. Viewresolver configuration To resolve the logical view name to Detailed View technology5, the Processor (page controller) configuration. For functional processing
SPRINGMVC Working principle