[spring topic] "principle series" the operating principle of spring MVC (supplementary Revision)

Haoyu Tianshang 2022-02-13 07:45:19 阅读数:802

spring topic principle series operating

Undertake relevant previous SpringMVC Process analysis of framework technology

Initialization flow (initStrategies)

Execute the process

Find relevant HandlerMapping

Ask to DispatcherServlet Class to perform related HandlerMapping aggregate , Find the corresponding type of HandlerMapping Object implementation class , If it is general, use notes (@RequestMapping) Injected implementation class (RequestMappingHandlerMapping) class ,

HandlerMapping Implementation class RequestMappingHandlerMapping object

find Spring In the container @Controller/@RestController annotated bean And being @RequestMapping Annotated classes and methods .

HandlerMapping Attribute HandlerMethod object

HandlerMethod yes Method as well as Parameter Of helper class. stay HandlerMapping Constructed in ,
And in HandlerAdapter Is used in .

HandlerExecutionChain object

When the corresponding HandlerMapping After the implementation class of the object , Next, return to DispatcherServlet Class object , Need to build or get relevant HandlerExecutionChain object , There are many additional components inside , for example :interceptor Interceptor .

HandlerAdapter object

according to HandlerExecutionChain Medium Handler, In the corresponding HandlerAdapter Collection found support for this Handler Of HandlerAdapter, Call related HandlerMethod Object methods , Use HandlerAdapter obtain ModelAndView Object returns to DispatcherServlet.

RequestMappingHandlerAdapter

Find the corresponding RequestMapping Of HandlerAdapter Object implementation class RequestMappingHandlerAdapter Object operation processing .

HandlerInterceptor Interceptor
  • Front interceptor :HandlerInterceptor-preHandle
  • Post blocker :HandlerInterceptor-postHandle
HandlerExceptionResolver exception handling

Exceptions may occur in the above operation processing methods , Use HandlerExceptionResolver Strategy solution .

RequestMappingHandlerAdapter Processing operation of

  • HandlerMethodArgumentResolverComposite: The object handles and contains multiple internal HandlerMethodArgumentResolver aggregate .
    • HandlerMethodArgumentResolver: Parsing mechanism for parsing related method entry parameters !
  • HandlerMethodReturnValueHandlerComposite: The object handles and contains multiple internal HandlerMethodReturnValueHandler aggregate .
    • HandlerMethodReturnValueHandler: The object handles and operates on the return value of the method

HandlerMethodArgumentResolver Parser for parameter entry

RequestParamMethodArgumentResolver

Handle @RequestParam The parameter modified by the annotation :HandlerMethodArgumentResolver One of the implementation classes of :RequestParamMethodArgumentResolver.

RequestResponseBodyMethodProcessor

Handle @RequestBody The parameter modified by the annotation :HandlerMethodArgumentResolver Implementation class of

HandlerMethodReturnValueHandler Parameter returns the operation parser

RequestResponseBodyMethodProcessor

Handle @ResponseBody Annotation decorated return value :HandlerMethodReturnValueHandler Implementation class of

ModelAndViewMethodReturnValueHandler

The processing return value type is ModelAndView Object return value :HandlerMethodReturnValueHandler Implementation class of

ViewResolver view resolver

take ModelAndView Analyze and process the object data and data page template ViewResolver object , Generate relevant View object . And return the relevant response:freemarker, jsp. json, xml etc. .

HandlerInterceptor Close the deal

Finally complete the interceptor :afterCompletion Method of operation .

copyright:author[Haoyu Tianshang],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130745170110.html