In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the knowledge points of Spring MVC components". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the knowledge points of Spring MVC components".
1. The execution process of SpringMVC (see figure below)
(1) the user sends a request to the front controller DispatcherServlet.
(2) DispatcherServlet receives a request to call the HandlerMapping processor mapper.
(3) the processor mapper finds the specific processor (which can be found according to the xml configuration and comments), generates the processor object and the processor interceptor (if any) and returns it to DispatcherServlet.
(4) DispatcherServlet calls the HandlerAdapter processor adapter.
(5) the HandlerAdapter calls the specific processor (Controller, also known as the back-end controller) after adaptation.
(6) the completion of Controller execution returns ModelAndView.
(7) HandlerAdapter returns the controller execution result ModelAndView to DispatcherServlet.
(8) DispatcherServlet passes the ModelAndView to the ViewReslover view parser.
(9) the specific View is returned after ViewReslover parsing.
(10) DispatcherServlet renders the view according to View (that is, populating the model data into the view). DispatcherServlet responds to the user.
2. Parsing of SpringMVC components
(1) Front-end controller: DispatcherServlet
When the user request arrives at the front-end controller, it is equivalent to the DispatcherServlet dispatcher Servlet in the MVC mode, which is the center of the whole process control. It calls other components to deal with the user's request. The existence of Servlet reduces the coupling between components.
(2) processor mapper: HandlerMapping
HandlerMapping is responsible for finding the Handler processor according to the user's request. SpringMVC provides different mappers to achieve different mapping methods, such as configuration file mode, implementation interface mode, annotation mode and so on.
(3) processor adapter: HandlerAdapter
Processors are executed through HandlerAdapter, which is an application of the adapter pattern, and more types of processors can be executed by extending adapters.
(4) processor: Handler
It is the specific business controller to be written in our development. The user request is forwarded to Handler by DispatcherServlet. The specific user request is processed by Handler.
(5) View parser: View Resolver
View Resolver is responsible for generating the View view of the processing result. View Resolver first parses the logical view name into the physical view name, that is, the specific page address, and then generates the View view object. Finally, the View is rendered and the processing result is displayed to the user through the page.
(6) View: View
The SpringMVC framework provides support for many View view types, including jstlView, freemarkerView, pdfView, and so on. The most common view is jsp. In general, we need to display the model data to the user through the page through the page tag or page template technology, and the programmer needs to develop the specific page according to the business needs.
3. Analysis of SpringMVC annotations
@ RequestMapping
Function: used to establish the correspondence between the request URL and the request processing method.
Location: on the class, request the first level of URL to access the directory. If it is not written here, it is equivalent to requesting the second level of the URL to access the directory on the root directory method of the application, together with the first level directory marked with @ ReqquestMapping on the class to form the access virtual path.
Attribute: value is used to specify the URL of the request. It has the same effect as the path attribute; method is used to specify how the request is made; and params is used to specify conditions that restrict request parameters. It supports simple expressions. The key and value that require the request parameters must be exactly the same as the configuration.
For example:
Params = {"accountName"}, indicating that the request parameter must have accountName
Params = {"moenyroom100"}, indicating that the money in the request parameters cannot be 100
(1) introduction of mvc namespace
(2) component scanning
SpringMVC is based on the Spring container, so when performing SpringMVC operations, you need to store the Controller in the Spring container, and if you use @ Controller annotation, you need to use it for component scanning.
4. XML configuration analysis of SpringMVC
SpringMVC has a default component configuration, which is configured in the DispatcherServlet.properties configuration file with the address org/springframework/web/servlet/DispatcherServlet.properties, and the default view parser is configured in this file, as follows:
Org.springframework.web.servlet.ViewResolver=org.springframework.web.servlet.view.Inter
NalResourceViewResolver
(1) View parser
We can modify the prefix of the view by property injection.
Thank you for your reading, these are the contents of "what are the knowledge points of Spring MVC components". After the study of this article, I believe you have a deeper understanding of what the knowledge points of Spring MVC components have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.