SPRINGMVC Learning (II)--SPRINGMVC Architecture and components

Source: Internet
Author: User

I believe that through the previous text of the study, has already springmvc this framework somewhat some understanding. Remember the SPRINGMVC process in the previous article?

This figure roughly describes the whole process of springmvc, this flowchart is relatively easy to understand, the following I will give SPRINGMVC frame structure diagram, This figure is more complex, but after my meticulous explanation, I believe we can understand deeply.

SPRINGMVC Frame Structure

The SPRINGMVC framework structure is as Follows:

Below I will explain the SPRINGMVC frame structure in Detail.

Architecture process
    1. The user sends the request to the front controller dispatcherservlet.
    2. Dispatcherservlet received a request to call the Handlermapping processor Mapper.
    3. The processor mapper finds the specific processor based on the request url, and the Processor object and processor Interceptor (if Any) are returned to Dispatcherservlet.
    4. Dispatcherservlet calls the processor through the Handleradapter processor Adapter.
    5. The execution processor (controller, also known as the Back-end controller).
    6. Controller execution is finished returning MODELANDVIEW.
    7. Handleradapter returns the controller execution result Modelandview to Dispatcherservlet.
    8. Dispatcherservlet passes the Modelandview to the Viewreslover view Parser.
    9. Viewreslover parse to return to the specific VIEW.
    10. Dispatcherservlet view is rendered (the model data is populated into the view).
    11. The Dispatcherservlet responds to the User.

There is a rough explanation of the SPRINGMVC frame structure above, and I will do a more nuanced lecture.

  1. Who does the browser send the request to? First to the front-end controller, that is, all requests are sent to the front-end controller, the front-end controller is the portal of all requests, but the front controller cannot process the business request, it is just a request forwarding.
  2. Who will handle the business request? Handler processor to really handle business requests, so the question is, how does the front controller find this handler processor? The processor mapper records the mapping between the requested URL and the processing method, How is this mapping relationship built up? By @requestmapping this annotation to build up, this mapping relationship is equivalent to a map (key-value this form), key is the request Url,value is the handler of Processing. now, the front controller to get this request, to find the corresponding handler, how to find it? To find the processor mapper, ask it to request who to handle?
  3. The processor mapper will find the corresponding processor based on the URL you requested, it will error if it is found, and if it does, it will return a processor execution chain, which in addition to the handler, there are interceptors (here we can develop our own interceptors), It is then returned to the front controller.
  4. The front-end controller still can't handle the business request, and There's another thing to do, because returning handler, it doesn't know what the handler is, because handler in spring MVC can be a non-annotated form, except in the form of annotations. non-annotated form We generally do not use), the front-end controller does not know what the handler is exactly what type, then there is no way to execute it, it must find something to do, then it will give this matter to another component to handle, This component is called the processor adapter, This processor adapter is to fit different types of handler. It will choose different types of adapters to execute according to your different types of handler.
  5. If the current handler is in the form of annotations, then it chooses the processor adapter in the form of annotations to perform this handler. The handler executes, that is, the method in our controller class executes, and after the method executes, the business inside is Processed.
  6. After the business process, a modelandview is finally Returned. Processor adapter It is useless to get this result, its function is to execute this handler, after the execution of this handler, it Finished.
  7. When You're done, you get the return result, and then it throws the return result to the front controller intact, and the processor adapter is Finished.
  8. Front controller to get this modelandview, it still has no way to deal with, it still can't return html, when it to find the corresponding jsp, because Modelandview contains the model and contains the view, this view specifies who we want to render this Data. We want to render the data, then it will find a view parser to parse this view, because this view is also a lot of (our most common view is jsp, in addition to jsp, in fact, there are other, for example, can also be a report, also can be a pdf, it can be freemaker, etc.), It will look for a different view parser to Handle. Since our most commonly used view is jsp, it finds the corresponding view parser for the jsp.
  9. Find this view parser, which will parse the view and return a View object after Parsing.
  10. finally, We call this view parser render view this process, rendering the view of the process is actually for our jsp, is to render this data into Html.
  11. After the final rendering into html, it responds to the User.

Through the above analysis, do you have a better understanding of the SPRINGMVC architecture process? I might have written a bit more about it, but it was a good thing for me to understand and hope for you too.

Component description

The following components typically provide implementations using the Framework:

    • Dispatcherservlet: Front Controller
      The user request arrives at the front controller, it is equivalent to the MVC pattern C,dispatcherservlet is the entire process Control center, by it calls other components processing User's request, The Dispatcherservlet existence reduced the coupling between the Components.
    • Handlermapping: Processor Mapper
      Handlermapping is responsible for the User's request to find handler is the processor, SPRINGMVC provides different mapper implementation of different mapping methods, such as: configuration file mode, interface mode, annotation and so On.
    • Handler: processor
      The handler is the Back-end controller of the Dispatcherservlet front-end controller, which is processed under the control of Dispatcherservlet handler to specific user Requests. since handler involves specific user business requests, The general situation requires programmers to develop handler based on business Requirements.
    • Handladapter: Processor Adapter
      The processor is executed through the handleradapter, which is an application of the adapter pattern that can be performed on more types of processors through the extension adapter.
    • Viewresolver: View Resolver
      Viewresolver is responsible for generating a view view of the processing results, viewresolver First resolves the logical view name to the physical view name that is the specific page address, then generates the view object, and finally renders the view to show the user the results of the Processing.
    • View: views
      The SPRINGMVC framework provides support for many view view types, including: jstlview, freemarkerview, pdfview, and so On. The most common view we use is jsp. in general, the model data needs to be presented to the user through page labels or page template technology, and the programmer needs to develop specific pages based on the business Requirements.
Summarize

In the various components of springmvc, the processor mapper, processor adapter, and view Resolver are called the three components of the SPRINGMVC. Actually need programmer development of two big pieces: one is handler, one is jsp, so, in fact, and Struts2 is almost, so don't be above that a series of flow to fool Around.

SPRINGMVC Learning (II)--SPRINGMVC Architecture and components

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.