SpringMVC from entry to mastery

http://www.imooc.com/article/3804

The first chapter of SpringMVC from entry to mastery

Introduction to the first section: SpringMVC is a module of the Spring framework. Spring and SpringMVC do not need to be integrated through an intermediate integration layer. SpringMVC is an MVC-based WEB framework. The application of MVC design pattern in B/S:

image description

Explanation to the above figure ①: The browser sends a request to the controller (the role of the controller must be known here) ②: The controller cannot process the request and must hand it over to the model layer to process and then access the database ③: The model layer returns the processed result To the control layer ④: The control layer responds the logical view to the browser (the browser displays the rendered view) Section 2 SpringMVC Principle First remember the principle. Then explain the principle. The focus of this article is also covered in each chapter. The schematic diagram is as follows:

image description

The filter tag in xml is) 2. The front-end controller will go to the handler mapper (HandlerMapping), and the handler mapper will find the specific handler according to the request url, and generate the handler object and handler interceptor (if any) ) are returned to DispatcherServlet together. 3. According to the handler returned by the handler mapper, DispatcherServlet will find a "suitable" handler adapter (HandlerAdapter). 4. The handler adapter HandlerAdpater will execute the handler (when Handler is developed, it will be called controller or backend). The action of the controller in struts2 is also a back-end controller) before execution, there will be converters, data binding, validators, etc. to complete the above before going to execute Handler 5, the back-end controller Handler returns a ModelAndView object 6, the processor adapter HandlerAdpater will return this ModelAndView to the front controller DispatcherServlet. The front controller will pass the ModelAndView object to the view resolver ViewResolver. 7. View resolver ViewResolver returns the logical view after parsing the ModelAndView object. 8. The front-end controller DispatcherServlet renders (data fills) the logical view and returns the real physical view and responds to the browser. Description of the components: 1. DispatherServlet: The user request from the front controller reaches the front controller, which is equivalent to C in MVC, and the DispatherServlet is the core of the whole process. It calls other components to process the user's request, and the existence of the front controller is reduced. the coupling between other components. 2, HandlerMapping: The function of the processor mapper is like going to a movie to take a movie ticket and find the seat according to the seat number on the movie ticket. The seat is the Handler, and the movie ticket and the seat number above are the URL HandlerMapping is responsible for finding it according to the user's request Handler is a processor, and springmvc provides different mappers to implement different mapping methods, such as: configuration file method, implementation interface method, annotation method, etc. 3. Handler: The processor Handler is a back-end controller. Under the control of the front-end controller, the back-end controller processes specific user requests. Handler involves specific user business requests, so in general, programmers need to be based on the business. Requirement development. 4. HandlerAdapter: The processor adapter executes the processor through the HandlerAdapter, which is the application of the adapter mode. More types of processors can be executed through the adapter. The movie is played in 3D and you can't see it clearly, so the movie theater tells you that you must wear 3D glasses if you want to see the movie clearly. That is to say, Handler can be executed only if it meets certain requirements. 5. ViewResolver: The view resolver ViewResolver is responsible for generating the View view from the processing result. The ViewResolver first resolves the logical view name into the physical view name, that is, the specific page address, then generates the View view object, and finally renders the View to display the processing result on the page. to users. Interested students, I hope to be able to memorize this first chapter. Because once you know struts1 or struts2, etc., you can basically know what the framework is like at the end of the first chapter, and the rest is how to implement it. ViewResolver first resolves the logical view name into a physical view name, that is, a specific page address, then generates a View view object, and finally renders the View to display the processing results to the user through the page. Interested students, I hope to be able to memorize this first chapter. Because once you know struts1 or struts2, etc., you can basically know what the framework is like at the end of the first chapter, and the rest is how to implement it. ViewResolver first resolves the logical view name into a physical view name, that is, a specific page address, then generates a View view object, and finally renders the View to display the processing results to the user through the page. Interested students, I hope to be able to memorize this first chapter. Because once you know struts1 or struts2, etc., you can basically know what the framework is like at the end of the first chapter, and the rest is how to implement it.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326860303&siteId=291194637