Introduction to Spring MVC

Source: Internet
Author: User


Spring MVC


1. MVC

The MVC idea is to classify the various components of the system, and different components play a role. The components in the system are then separated into different tiers, which are tightly constrained within their layers. The components in the same layer should remain cohesive and roughly at the same level of abstraction, while the layers are loosely coupled in a way that guarantees good encapsulation. MVC separates an application's input, processing, and output installation model (model), view (view), and controller (director) into three parts, so that an application can be divided into model layers, view layers, and control layers. The 3 layers work together with minimal coupling to improve the scalability and maintainability of the application system.

Model (models). The model layer represents the data and business logic, it controls the processing and updating of the data, in general, the process of business processing for the view layer and control layer are black-box operations, the model layer accepts the view request data, and return the final processing results to update the view layer.

View (views). The view layer is actually a concrete representation of the model layer's models, which are displayed by the data and then by the requirements. Although the view layer does not handle the data, the data that he transmits to the control layer is consistent with the data type of the model layer, that is, when the model data changes, the view layer changes as well.

Controller (director). The control layer joins the view layer and the model layer in the MVC pattern, which is the process of filtering the interaction information of the view layer and processing it at the corresponding business logic handler in the model layer. In a Web application, the view layer takes a message request (get, POST) to the control layer first. ), the control layer does not do any processing after receiving the request, but passes the request message to the model for business processing. Results are ultimately based on the model layer. The control layer updates the corresponding view display to the browser (user) .

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6D/B8/wKioL1VqocWgGL2aAAELIdHrLCw023.jpg "title=" Picture 4.png "alt=" Wkiol1vqocwggl2aaaelidhrlcw023.jpg "/>

Figure 2-5 MVC layer Three relationship


2. MVC features

(1) Low coupling. The architecture is divided into three tiers, reducing the amount of coupling between layers, which is easy to program for scalability and maintainability.

(2) One-mode multi-view. A model can correspond to multiple views, improve the maintainability of the code, once the model has changed, easy to modify the program.

(3) separation. The data returned by the model is separated from the reality, and the returned data can be used in any kind of display technology, and the layers are only responsible for their own tasks.


3. Spring MVC

Spring MVC, as its name implies, is MVC, but it is based on spring. As shown in 2-6.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6D/BC/wKiom1VqoH3xqk5kAADc5VE-pyw478.jpg "title=" Picture 5.png "alt=" Wkiom1vqoh3xqk5kaadc5ve-pyw478.jpg "/>

Figure 2-6 Spring MVC schematic diagram

The workflow of Spring MVC:

(1) the client (browser) initiates a request to spring.

(2) The request is intercepted by the front-end controller (dispatcherservlet) and the corresponding mapping processor (Handle Mapping) is searched for processing the request.

(3) Dispatcherservlet Select one of the controllers (Controller) according to the handle mapping.

(4) After determining a specific controller, Dispatcherservlet passes the request to the selected controller, which processes the request and returns the final result of the processing to Dispatcherservlet.

(5) Dispatcherservlet uses the View parser (Viewresolver) to parse the received model data and determine the logical view name to return.

(6) Dispatcherservlet finds the corresponding view according to the view name and returns it to the client (browser).


This article is from the "You are ITER for bugs Live" blog, please be sure to keep this source http://king2.blog.51cto.com/8746235/1656828

Introduction to Spring MVC

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.