How Spring MVC Works

Source: Internet
Author: User

This article was reproduced from: http://blog.csdn.net/u012191627/article/details/41943393

Springmvc Framework Introduction

1) Spring MVC is a follow-up product of Springframework, which has been integrated into spring Web flow.

The Spring framework provides a full-featured MVC module for building WEB applications. Using spring's pluggable MVC architecture, you can choose to use a built-in spring web framework or a WEB framework such as Struts. With the policy interface, the Spring framework is highly configurable and includes a variety of view technologies, such as JavaServer Pages (JSP) technology, Velocity, Tiles, IText, and POI. The Spring MVC framework does not know which view to use, so it does not force you to use only JSP technology.

Spring MVC separates the roles of controllers, model objects, dispatchers, and handler objects, and this separation makes them easier to customize.

2) Spring's MVC framework consists mainly of Dispatcherservlet, processor mapping, processor (Controller), view parser, and view.

SPRINGMVC schematic diagram

Springmvc Interface Interpretation

Dispatcherservlet Interface:

Spring provides a front-end controller that all requests have to be distributed uniformly. Before Dispatcherservlet will distribute the request to the spring controller, it needs to navigate to the specific controller using the handlermapping provided by spring.

Handlermapping Interface:

Ability to complete customer requests to controller mappings.

Controller interface:

The above requests need to be handled for concurrent users, so when implementing the Controller interface, you must ensure that threads are secure and reusable.

The controller will process the user request, which is consistent with the role that struts action plays. Once the controller has finished processing the user request, the Modelandview object is returned to the Dispatcherservlet front-end controller, and the model and view are included in Modelandview.

From the macroscopic point of view, Dispatcherservlet is the controller of the whole Web application, and from the microscopic consideration, the controller is a control in the process of single HTTP request processing. Modelandview is the model and view that is returned during the HTTP request.

Viewresolver Interface:

Spring provides a view parser (Viewresolver) to look up a View object in a Web app, rendering the result to the customer.

SPRINGMVC Operating principle

1. Client request submitted to Dispatcherservlet

2. Query one or more handlermapping by the Dispatcherservlet controller to find the controller that handles the request

3. Dispatcherservlet submits the request to the controller

4. After the controller invokes the business logic processing, returns the Modelandview

5. Dispatcherservlet query One or more Viewresoler view resolvers to find the Modelandview specified view

6. The view is responsible for displaying the results to the client

Dispatcherservlet is the core of the whole spring MVC. It is responsible for receiving the HTTP request organization to coordinate the various components of spring MVC. Its main work has the following three items:

1. Intercept URL requests that match a specific format.
2. Initialize the webapplicationcontext that corresponds to the Dispatcherservlet context and associate it with the business layer, webapplicationcontext of the persistence layer.
3. Initialize the various components of spring MVC and assemble them into the dispatcherservlet.

<mvc:annotation-driven/> Description:

is a shorthand form, allowing beginners to quickly apply the default configuration scheme, the default registration defaultannotationhandlemapping and annotionmethodhandleadapter The two beans, the two beans, The former corresponds to the class level, the latter corresponds to the method level, and the defaultannotationhandlermapping and Annotationmethodhandleradapter on the polygon are Spring @Controller Required to distribute the request. Annotation-driven scans the annotations on classes in the specified package, and the commonly used annotations are: Copy code @controller Declare the action component @service declare the Service component @Service ("Mymovielister") @ Repository declares that DAO components @component refer to components when they are not well categorized. The @RequestMapping ("/menu") request mapping @resource for injection, (as provided by Java EE) is assembled by name by default, @Resource ( Name= "Beanname") @Autowired used for injection, (Srping provided) default assembly by Type @transactional (Rollbackfor={exception.class}) Transaction Management @responsebody@scope ("prototype") sets the scope of the bean

How Spring MVC Works

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.