Home > Java > javaTutorial > body text

SpringMVC workflow

angryTom
Release: 2020-02-14 14:41:09
Original
2381 people have browsed it

SpringMVC workflow

SpringMVC workflow

1. Introduction to SpringMVC

SpringMVC is a Spring-based implementation It is a request-driven lightweight Web framework that adopts the Web MVC design pattern. It uses the idea of ​​​​the MVC architectural pattern to decouple the responsibilities of the web layer and manage the life cycle of the objects required by the application. It provides a lot of tools to simplify daily development. Great convenience.

SpringMVC provides the main switch DispatcherServlet; request processing mapper (Handler Mapping) and processing adapter (Handler Adapter), view resolver (View Resolver) for view management; action processor Controller interface (including ModelAndView, and Processes request and response objects (request and response), has flexible configuration, supports file upload, simple data conversion and other powerful functions.

(Related video tutorial sharing: java video tutorial)

2. Workflow and introduction

SpringMVC workflow

(1) The client sends a request through the url

(2-3) The core controller Dispatcher Servlet receives the request, finds the corresponding handler through the system or custom mapper configuration, and sends The controller mapped by the url is returned to the core controller.

(4) Find the system or default adapter through the core controller

(5-7) From the found adapter, call the processor that implements the corresponding interface, and return the result to the adapter, The result contains data model and view objects, which are then returned to the core controller by the adapter

(8-9) The core controller passes the object combining the obtained data and the view to the view parser, and obtains the parsed The result is responded to by the view parser to the core controller

(10) The core controller returns the result to the client

3. Adapter role

The mapper involved in SpringMVC, the role of the view parser is not difficult to understand. The mapper is responsible for mapping the url of the front-end request to the configured processor. The view parser parses the final result, but why does it need to go through a layer of adapters in the middle? Well, why not directly execute and return after finding the controller through the mapper?

That’s because SpringMVC provides a variety of interface implementations for business processors (such as implementing the Controller interface), and the adapter is used to ultimately select a different type from the registered one based on what interface the processor implements. The Handler Adapter is matched and finally executed. For example, SimpleControllerHandlerAdapter supports controllers that implement the controller interface. If the controller you write implements the controller interface, then SimpleControllerHandlerAdapter will execute the specific methods in the controller you wrote. Complete the request.

For more SpringMVC related tutorials, please pay attention to the Java Tutorial column.

The above is the detailed content of SpringMVC workflow. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template