Spring MVC architecture and Processing request controller

Source: Internet
Author: User
Tags map data structure

Spring MVC architecture and Processing request Controller one: MVC design pattern:

(1.) Data access interface: DAO layer

(2.) Processing the Business Logic layer: Service layer

(3.) Data entity: POJO

(4.) Be responsible for receiving and processing the previous request: Service

(5.) responsible for front-end page display: JSP

This architecture pattern is the MVC design pattern, which is a software architecture model of software engineering. It is mandatory that the software system input, processing and output of the separation, the software system is divided into three basic parts: model, view (Controller)

Analytical:

View: Responsible for formatting the data and presenting it to the customer

Controller: Responsible for receiving and forwarding requests, responding to customers

Model: The Model object has the most processing tasks, is the main part of the application, and is responsible for processing and implementing the data

Two: MVC two modes:

JSP MODEL1: When the business process is relatively simple, the function of the controller can be given to the view to implement, this pattern is collectively known as JSP MODEL1

JSP MODEL2: The equivalent of JSP MODEL1 when the business process is complex, that is, the need to give the business process to the controller to achieve, JSP focus on the display of the map can

MVC processing Process

(1.) The first view is to provide the system with the user interface and send the user to the controller.

(2.) The controller receives the user request and decides which model to call to process

(3.) The model is processed according to the user request and returns the processing result.

(4.) the controller invokes the corresponding view to format the data returned by the model and renders it to the customer through the view, based on the return processing result.

MVC pros and Cons:

Advantages:

(1.) Multiple views share a model, greatly improving the usability of the Code

(2.) MVC three modules independent of each other, loosely coupled architecture

(3.) Controller improves application and flexibility and availability

(4) Benefits of software engineering management

Disadvantages:

(1.) Complex principle

(2.) Increased complexity of system architecture and implementation

(3). Inefficient access to model data by view

Three: Spring MVC framework Introduction flowchart

1:spring MVC Environment Building

(1.) Importing JAR files

(2.) Configuring the servlet in Web. xml

(3.) Create a SPRINGMVC configuration file (springmvc-servlet.xml) (the controller that handles the request)

(4). Create a Controller

(5.) CREATE View

(6.) Deployment Run

(7.) Change Handlermapping (processor mapping)

<property name= "suffix" value= ". jsp"/>

</bean>

</beans>

Four:
    1. Spring MVC Framework Architecture Request processing flow

(1.) First the user sends the request to the front controller (dispatcherservlet) front-end controller according to the request information, decide which control page (Controller) to process, and delegate the request to him, that is, the service controller of the Control logic section D

(2.) After the page controller receives the request, carries on the business processing, processing completes returns a Modelandview (model data name and logical view name)

(3.) The front controller retracts the controller, then selects the corresponding view name according to the logical view name and passes the model data in order to display the view rendering

(4.) The front controller retracts the controller again, returning the corresponding result to the customer, at which point the entire process ends

    1. The architecture of the Spring MVC framework

(1.) The client makes an HTTP request, and the Web application server receives the request, and if it matches the Dispatcherservice request mapping path (specified in Web. xml), the Web container will hand over the request to Dispatherservice processing (DKZ)

(2.) Dispatherservice receives the request will be based on the requested information (including URL, request parameters, HTTP method, etc. and Handlermapping configuration (in <servicename>- Servlet.xml), find the method to process the request K

(3.) when Dispatherservice finds the corresponding current request handler based on the handlermapping, the handler is encapsulated by Handleradater, and the Handler.handleradapter is invoked on a unified adapter interface , can be understood as the specific use of handler to work people. Three methods

Supports (Object handler) method to determine whether a handler can be used

Handle method: Use handler to work in detail

Getlastmodified method to get the last-modified of a resource

(4.) in the time before the request information reached the real call handler processing method, SPRINGMVC also completed a lot of work, he will be the request information in a certain way to convert and bind to the request method in the parameter, for the incoming parameters of the object will be data conversion, formatting and data calibration, and so on, these are done, and finally the real call The handler processing method carries on the corresponding data logic processing.

(5.) After the processor finishes business processing, it returns a Modelandview object to the Dispatcherservlet,modelandview object that contains the logical view name and model data information.

(6.) The Modelandview object contains "logical view name" rather than a real view object, and dispatherservice resolves the logical view name to a real view object through Viewresolver, and the view of course data presentation can be a JSP , Xml,pdf,json and many other data formats,

(7.) When you get the final view object after view, Dispatherservice uses the model data from the Modelandview object to render the view.

(8.) The final client receives a response message, depending on the configuration, either a normal HTML page or an XML, or JSON-formatted data. Z

    1. Features of the Spring MVC framework

(1) Clear role Division.

(2.) Flexible function configuration

(3.) provides a large number of controller interfaces and implementation classes

(4.) really not related to the View layer implementation (JSP,VELOCITY,XSLT, etc.)

(5.) Internationalization support

(6.) interface-oriented programming

(7.) provides a complete set of processes for Web application development

Five:

1. Parameter passing: The simplest method is to direct the parameters of the Controller method into the parameter

@RequestMapping Mapping:

(1.) mapping by requesting a URL D

(2.) The request method is mapped by the request parameter

2. Parameter passing (Controller to View)

(1.) Modelandview Common methods

If the return value of the method processed by the processor is Modelandview, including the view information and the model data information, Spring MVC will be able to render the data on the views model as soon as the object is available.

*. Add model data

*. Setting the View

2.Model

In addition to using the Modelandview object to return model data, we can also use the model object provided by spring MVC to complete the delivery of the models ' data. K

3.Map

Through the previous study of model and Modelandview objects, we can also use the spring MVC model, which is a map data structure, which can be processed using map as the reference.

[Email protected]

If you want to put the data object into the data model, you need to use this annotation before the corresponding entry, and then we will only do a simple understanding.

[Email protected]

This annotation can be stored in the httpsession in the model so that the attribute is shared among multiple requests, with a simple understanding. Z

VI: View Resolver
    1. All view parsers implement the Viewresolver interface as follows:

2.Spring MVC uses the view parser to perform the work of view parsing, parsing the logical view name returned by the controller's processing method into a real view object

Spring MVC architecture and Processing request controller

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.