Spring MVC Architecture and Processing request controller

Source: Internet
Author: User

Introduction to the 1.Spring framework

The Spring MVC Framework has an MVC framework that separates data, business, and presentation well by implementing the Model-view-controller pattern. In the spring MVC framework, the controller replaces the service to take over the responsibilities of the controllers, which receives the request, invokes the appropriate model for processing, and returns the processing result after the processor has completed the business process. The controller invokes the appropriate view and renders a view of the processing results, and the end client gets the response information.

2.MVC Pros and cons

    • Advantages
      • Multiple views share a model, which greatly improves the reusability of code
      • MVC three modules independent of each other, loosely coupled architecture
      • Controller improves flexibility and configuration of applications
      • It is advantageous to the engineering management of soft drop
    • Disadvantages
      • Complex principle
      • Adds complexity to system architecture and implementation
      • Inefficient access to model data

3.Spring MVC Environment Building

    • Introducing JAR Files
    • Spring MVC Configuration
      • Configuring the servlet in Web. XML, defining Dispacherservlet
      • Create a spring MVC configuration file
    • Create a controller (the director that handles the request)
    • CREATE view
    • Deployment Run

Request processing flow for the 4.Spring MVC framework

    • First, the user sends 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 part of the previous controller
    • After the page controller receives the request, it functions, first it needs to collect and bind the request parameters to an object, which is called the Command object in spring WEB MVC, validates it, and then delegates the command object to the business object for processing. ; Returns a modelandview (model data and Logical view name) after processing is completed;
    • The front controller reclaims control, and then, based on the returned logical view name, selects the appropriate view to render, and the model data is passed in for the view to render;
    • The front controller reclaims control again, returning the response to the user
5.Spring Workflow Description
    • The user sends a request to the server, and the request is captured by the spring front control servelt Dispatcherservlet;
    • Dispatcherservlet parses the request URL to get the request Resource Identifier (URI). Then, according to the URI, call handlermapping to get all the related objects of the handler configuration (including the handler object and the interceptor corresponding to the handler object), and finally return as a Handlerexecutionchain object;
    • Dispatcherservlet according to the obtained handler, choose a suitable handleradapter. ( note : If Handleradapter is successfully obtained, the Interceptor Prehandler (...) will start executing. Method
    • Extract the model data from the request, populate the handler entry, and start executing the handler (Controller). In the process of populating the handler, depending on your configuration, spring will do some extra work for you:
      • Httpmessageconveter: Converts a request message (such as JSON, XML, and so on) into an object, converting the object to the specified response information
      • Data transformation: Data conversion for a request message. such as string conversion to Integer, double, etc.
      • Data is initialized: Data is formatted for the request message. such as converting a string into a formatted number or a formatted date
      • Data validation: Verifying the validity of the data (length, format, etc.), and verifying that the results are stored in Bindingresult or error
    • Handler returns a Modelandview object to Dispatcherservlet when execution is complete;
    • Based on the returned Modelandview, select a suitable viewresolver (must be viewresolver already registered in the spring container) to return to Dispatcherservlet;
    • Viewresolver combining model and view to render the view
    • Returns the rendered result to the client.

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.