April 14, 2023
Spring MVC consists of components such as DispatcherServlet, View Resolver, Interceptor, Handler, and View, with DispatcherServlet playing the crucial role of the front controller.
DispatcherServlet receives all requests from web browsers.
DispatcherServlet retrieves a Handler object from the HandlerMapping that can process the given request.
DispatcherServlet retrieves a HandlerAdapter object that can invoke the retrieved Handler.
If there are interceptors to be applied to the Handler object that handles the Controller, DispatcherServlet calls the preHandle method of all interceptor objects.
DispatcherServlet executes the method of the actual Controller through the HandlerAdapter object and obtains a ModelAndView.
If there are interceptors to be applied to the Handler object that handles the Controller, DispatcherServlet calls the postHandle method of all interceptor objects. DispatcherServlet passes the view name obtained from the ModelAndView in step 5 to the ViewResolver to obtain the View object necessary for the response.
DispatcherServlet calls the render method of the View object obtained in step 7, passing the Model of the ModelAndView obtained in step 5 as a parameter to perform page rendering.
DispatcherServlet returns the rendered page as a response to the user.