Spring MVC processing and Spring MVC Processing
1. First, the user sends a request,DispatcherServletWill intercept the request,DispatcherServletAfter receiving the request, do not process it, But parse the URL to obtain the correspondingURI(Resource identifier ).
2.DispatcherServletCallHandlerMapping,HandlerMappingThe role is to resolveRequest Link(URI), And thenRequest Link, Find the appropriate ProcessorHandler(SaidHandler, That isControllerOrAction),HandlerMappingHowever, it is not a simple return processor. Instead, it encapsulates the processor and interceptor to form a processor execution chain (HandlerExecuteChain) ReturnDispatcherServlet.
3.DispatcherServletBased on the obtainedHandlerType, select a suitableHandlerAdapter.
4. InHandlerAdapterCall before executionHandlerInterceptorThe preHander () method.
5.HandlerAdapterDefines how to process the request policy, through the requestURI, RequestMethodAnd ProcessorRequestMappingDefinition, final callHandler(Controller) To process the request and complete the function.
6.ControllerDirectionDispatcherServletReturnsModelAndViewObject (including model data, logical view name)
7. Based on the returned
ModelAndView, Select a suitable
ViewResolver(It must have been registered in the Spring container.
ViewResolver) Return
DispatcherServlet. 8.
DispatcherServletAccording
ModelAndViewModel data in the instance. The logical view name returns the information
ViewResolver.
9.
ViewResolverProcess the view and return it to the client. For xml configuration. in the xml configuration file, remember to register HandlerMapping, HandlerAdapter, and ViewResolver. If not, Spring will use the default registration. add the Controller class to facilitate dependency injection. If it is an annotation configuration, you need to add the class in Spring. add in xml
<Context: annotation-config/> <! -- Simplified configuration and combination of @ Resource, @ PostConstruct, @ PreDestroy, and other annotations --> <context: component-scan/> <! -- Automatically scan the package path --> <mvc: annotation-drivent/> <! -- It automatically registers the bean ultannotationhandermappint and AnnotationHanderAdapter beans. However, the disadvantage is that the interceptors attribute cannot be injected and the interceptor cannot be specified. -->