Understand the SpringMVC framework and basic workflow

Although the development process of traditional native JSP+Servlet is simple and clear, JSP page transfers data to Servlet, Servlet organizes data (logic development) or extracts data from database and then forwards it to JSP page, but it seems to only stop there. , we all know that our request and response depend on the url. When we want to program around the url, the pure JSP+Servlet only has a filter that works before reaching the corresponding Servlet, but if we want to To do some work after servlet forwarding or redirection? A url corresponds to a servlet. The url required by the project is slightly more complicated, and the number of corresponding servlets will be very large. Many problems will not be discussed here, and these problems are basically solved in SpringMVC.

  SpringMVC develops Web around Servlet, and the implementation of code also depends on Spring development, otherwise it will not be called SpringMVC. The focus of this article is on the workflow of SpringMVC, and does not design specific code development, so it is not required to master Spring. Knowledge

  1. Starting from the first point, the beginning of the request is of course the url accessed by the source of the user, and then the work of SpringMVC officially begins, just like a person entering the city, he must go through the city gate before entering, and the request is the same, he must first After a front controller called Dispatcher Servlet,

  2. After that, you always have a work place (the request needs work), but it doesn't recognize the way (where the request needs to be analyzed), so you need to find the map first, then Find the location on the map. In SpringMVC, the Dispatcher Servlet is the first to find the Handler Mapper, which maps the boss (HandlerAdapter) that finds the work point.

  3. Here we just know how to find the work point, and the path starts from the city gate (Dispatcher Servlet front controller). We found the HandlerAdapter that instructed us to work according to the guide of the map (information in the HandlerMapper component).

  4. The boss instructs us to work. At this time, we incarnate as employees (Handler, that is, the event corresponding to the request), and the content of our work is the method corresponding to the request url under the control layer (that is, C in MVC), and the work is completed. After that, we need to submit the work data to the boss (return the ModelAndView object to the HandlerAdapter)

  5. Then the boss will paste your work data on the city gate (return the ModelAndView object to the DispatcherServlet), and then present it to the exchange after some modification A businessman (user) of

  a businessman (user) looks at the basic process from the big picture. However, SpringMVC is much more complicated than this in the specific implementation. Basically, under the development of ordinary projects, after configuring the environment required by SpringMVC, we need to develop There are only the view layer and the control layer, and the code in the control layer generally has the implementation of the logic layer and the data layer.

  The following is the process I made with mind map, which is more intuitive than text.

  

Source code: minglisoft.cn/technology

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326508429&siteId=291194637