Spring MVC framework - principle and

 

  • Core components

    . 1 , the DispatcherServlet : front controller is responsible for scheduling the execution of other components, can reduce the coupling between different components, a Spring MVC core module.

    2 , Handler : a processor, accomplish specific business logic.
    . 3 , HandlerMapping : the DispatcherServlet by HandlerMapping maps the request to a different Handler .
    . 4 , HandlerInterceptor from : interceptors processor, an interface, if necessary to complete some interception process, can implement the interface.
    . 5 , HandlerExecutionChain : a processor to perform chain, comprising two parts, Handler and HandlerInterceptor from .
    . 6 , HandlerAdapter : a processor adapter, it can do some preprocessing prior to execution of business logic, data type conversion, packaging, etc., the DispatcherServlet by HandlerAdapter calling different Handler .
    7 ,ModelAndView : loading the data model and view information, as Hanlder processing result is returned to the DispatcherServlet .
    . 8 , ViewResolver : view resolver device, the DispatcherServlet into a physical view of the logical view through which the final rendering result of the response to the client.

 

  • work process

    1 , the client requests are DispatcherServlet received.
    2 , according to HandlerMapping mapped to the Handler .
    3 , create Handler and HandlerInterceptor .
    4 , Handler and HandlerInterceptor to HandlerExecutionChain form together back to the DispatcherServlet .
    . 5 , the DispatcherServlet by HandlerAdapter by adjusting Use Handler to complete the processing method of the service logic processing.
    6 , a return ModelAndView subject to the DispatcherServlet .
    7, The DispatcherServlet acquired ModelAndView object passed ViewResolver , resolves the logical view of the physical view View .
    8 , ViewResolver return a View to the DispatcherServlet .
    . 9 , the DispatcherServlet The View into ⾏ trekking view rendering (filling model data into view).
    10 , the DispatcherServlet the rendered view of the response to the client. 

                                          flow chart

 

 

  • how to use

   1, using the new IDEA project

   2, add dependency maven

 

  3, receive resources to create a folder

 

  4, in the resources folder, create a file manually springmvc.xml

 

  5, the new controller, write HelloHandler

 

  6, the new jsp page

 

  7, start the project, visit http: // localhost: 8080 / index

Guess you like

Origin www.cnblogs.com/zuichao123/p/12508438.html