Spring MVC Framework

Source: Internet
Author: User
Tags map data structure

The Spring Web MVC Framework is a request-driven web framework that is also designed with a front-end controller pattern and then distributed to the appropriate page controller (action/processor) based on the request mapping rules. First let's look at the process of Spring WEB MVC processing requests as a whole:

2.3.1, Spring Web MVC process of request processing

0-s

Figure 2-1

The following steps are performed:

1, the first user to send the request ———— > Front-end controller, the front controller according to the request information (such as URL) to decide which page controller to process and delegate the request to it, that is, the control logic of the previous controller, figure 2-1, 1, 2 steps;

2, after the page controller receives the request, carries on the function processing, first needs to collect and binds the request parameter to an object, this object calls the Command object in spring Web MVC, validates, and then delegates the command object to the business object for processing ; Returns a modelandview (model data and Logical view name) after processing; 3, 4, 5 steps in Figure 2-1;

3, the front controller retract control, and then according to the return of the logical view name, select the corresponding view to render, and the model data into the view rendering; steps 6, 7 in Figure 2-1;

4, the front controller again regain control, return the response to the user, figure 2-1, step 8;

2.3.2, Spring Web MVC architecture

1. Spring Web MVC Core architecture diagram, 2-2

Figure 2-2

The specific process steps for the core architecture are as follows:

1, the first user sends the request-->dispatcherservlet, the front controller receives the request not to carry on the processing, but entrusts to the other parser carries on the processing, as the unified access point, carries on the global flow control;

2, dispatcherservlet-->handlermapping, handlermapping will map the request to a Handlerexecutionchain object (containing a handler processor (page Controller) object, Multiple Handlerinterceptor Interceptors) object, through this strategy mode, it is easy to add a new mapping strategy;

3, Dispatcherservlet-->handleradapter,handleradapter will be the processor packaging as an adapter, thereby supporting a variety of types of processors, adapter design mode of application, so it is easy to support many types of processors;

4, handleradapter--> processor function processing method call, Handleradapter will be based on the results of the adaptation to call the real processor function processing method, complete the function processing, and return a Modelandview object (including model data, logical view name);

5, Modelandview logical View name----Viewresolver, Viewresolver will parse the logical view name into a specific view, through this strategy mode, it is easy to replace other view technology;

6, view--> rendering, the view will be based on the model data passed in to render, here the model is actually a map data structure, so it is easy to support other view technology;

7, return control to Dispatcherservlet, by Dispatcherservlet return response to the user, to this end of a process.

1. What is the request to the front controller? This should be described in the deployment description in Web. XML and explained in detail in HelloWorld.

2, the front-end controller How to select the page controller according to the request Information function processing? We need to configure handlermapping for mapping

3, how to support a variety of page controller it? Configure Handleradapter to support multiple types of page controllers

4. How does the page controller use the business object? It is expected that the dependency injection function of the spring IOC container must be utilized

5. How does the page controller return model data? Use Modelandview to return

6, the front controller how to select a specific view to render according to the logical view name returned by the page controller? Using Viewresolver for parsing

7. How do different view technologies use the corresponding model data? Because model is a map data structure, it is easy to support other view technologies

Here we can see the specific core development steps:

1. Dispatcherservlet deployment description in Web. XML to intercept requests to spring WEB MVC

2. Handlermapping configuration, which maps the request to the processor

3. Handleradapter configuration to support multiple types of processors

4, Viewresolver configuration, to resolve the logical view name to the specific view technology

5, the Processor (page controller) configuration, so as to perform functional processing

Spring WEB MVC Advantage

1. Clear Role Division: Front Controller ( DispatcherServlet ), request to processor mapping (handlermapping), processor adapter (handleradapter), view resolver (viewresolver), The processor or page controller (Controller), Validator (Validator), the Command object (the object that the command request parameter binds to is called the Commands object), and the Form object (the object that forms object provides to the form to display and submit to is called the form objects).

2, the Division of labor is clear, and the extension point is quite flexible, can easily expand, although almost no need;

3, because the command object is a Pojo, without inheriting the framework-specific API, you can use the command object directly as a business object;

4. Seamless integration with other spring frameworks is not available in other web frameworks;

5, adaptable, through the Handleradapter can support any class as a processor;

6, can be customized, handlermapping, viewresolver and so can be very simple customization;

7, powerful data validation, formatting, binding mechanism;

8. Using the mock object provided by spring can make the Web Layer unit test very simple;

9, localization, the interpretation of the theme of support, making it easier for us to international and theme switching.

10, the powerful JSP tag library, make JSP writing easier.

.................. There are support for RESTful styles, simple file uploads, contractual programming support with more than one configuration, annotation-based 0 configuration support, and so on.

Spring MVC Framework

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.