SpringMVC learning notes (1) ----- springMVC principles and springmvc principles

Source: Internet
Author: User

SpringMVC learning notes (1) ----- springMVC principles and springmvc principles
I. What is springmvc?

SpringMVC is a module of the spring framework. springMVC and spring do not need to be developed through the intermediate integration layer.

SpringMVC is a web framework based on mvc.

Spring web mvc and Struts2 both belong to the presentation layer framework, which is part of the Spring framework. We can see from the overall structure of Spring:

II. Application of mvc in B/s system

Mvc is a design model that everyone knows. You don't need to repeat it. You can directly look at the application of mvc in the B/s system:

 

1. the user initiates a request to the Controller)

Controls the data that receives user requests and delegates them to the model for processing.

2. The controller processes data through the Model and obtains the processing result.

The model usually refers to the business logic.

3. The model processing result is returned to the Controller.

4. The controller displays the model data in the View.

In the web, the model cannot display data directly in the view, and must be completed through the Controller. If the model is used in the C/S application, the data can be displayed in the view.

5. The controller returns the view response to the user.

Displays the data or processing results to the user through the view.

Iii. SpringMVC framework Introduction

 

(1) Initiate a request to the front-end controller (DispatcherServlet );

(2) the front-end controller requests HandlerMapping to search for Handler, which can be searched based on xml configuration and annotation;

(3) The processor er HandlerMapping returns Handler to the front-end controller;

(4). the front-end controller calls the processor adapter to execute Handler;

(5). The processor adapter executes Handler;

(6) The Handler completes the execution and returns ModelAndView to the adapter;

(7). The processor adapter returns ModelAndView to the front-end controller (an underlying object of springmvc framework, including Model and View );

(8). The front-end controller requests the view parser to parse the view and parse the true view (jsp...) according to the logical view name ...);

(9). The View parser returns the View to the front-end controller;

(10). The front-end controller performs view rendering. view rendering fills model data (in the ModelAndView object) into the request domain.

(11). The front-end controller responds to the user.

Components:

1. The front-end controller DispatcherServlet (which does not need to be developed by the attacker) is provided by the framework.

Function: receives the request and returns the response, which is equivalent to a forwarder and a central processor. DispatcherServlet reduces the coupling between other components.

When a user request arrives at the front-end controller, it is equivalent to c in mvc mode. dispatcherServlet is the center of the whole process control. It calls other components to process user requests, dispatcherServlet reduces the coupling between components.

2. processor HandlerMapping (development without siege lions is required)Provided by the Framework

Purpose: search for Handler based on the request url

HandlerMapping is responsible for finding Handler as the processor according to user requests. springmvc provides different ing modes for different mappers, such as configuration file mode, interface mode, and annotation mode.

3. processor adapter HandlerAdapter

Purpose: Execute Handler according to the specific rule (The rule required by HandlerAdapter ).

Execute the processor through the HandlerAdapter, which is an application in the adapter mode. You can execute more types of processors through the extended adapter.

4. processor Handler (developed by the attacker)

 Note: When writing Handler, follow the HandlerAdapter's requirements so that the adapter can correctly execute Handler.

Handler is the backend controller of the DispatcherServlet front-end controller. Under the Control of DispatcherServlet, Handler processes specific user requests.

Because Handler involves specific user business requests, it is generally necessary to develop Handler based on business needs.

5. View resolver (development of siege lions is not required)Provided by the Framework

Purpose: parse the view and parse the view based on the logical view name)

View Resolver is responsible for generating the View of the processing result. View Resolver first parses the logic View name into the physical View name, that is, the specific page address, and then generates the View object, finally, the View is rendered and the processing result is displayed on the page to the user. The springmvc framework provides many View types, including jstlView, freemarkerView, and lateral View.

Generally, the model data needs to be presented to users through the page tag or Page Template technology. The attacker needs to develop a specific page based on business needs.

6View (jsp development required for siege lions ...)

View is an interface that supports different View types (jsp, freemarker, pdf ...)

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.