Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of SpringMVC execution process

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "SpringMVC execution process example analysis", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "SpringMVC execution process example analysis" this article bar.

preface

Through in-depth analysis of Spring source code, we know that Spring framework consists of roughly six modules, such as Web module, database access technology module, aspect-oriented module, infrastructure module, core container module and module,

Among them, in the Web module of Spring Framework, there are many front-end technologies, such as SpringMVC,Spring WebSocket,Spring WebPortlet, etc. In this article, we mainly analyze SpringMVC module,

When analyzing SpringMVC technology, this article will analyze the execution process of SpringMVC in depth by interpreting SpringMVC source code, and studying UML diagrams of Spring core classes through compiler breakpoint debugging traces.

Spring Core Module

The Spring Core Module is shown below, where the Spring MVC module is located in the Web Module section of the Spring Framework.

Spring MVC implementation principle

The following figure is a more complete flowchart of SpringMVC. The solid line indicates the technology provided by SpringMVC framework, which does not need to be implemented by developers. The dotted line indicates that developers need to implement it.

Brief analysis of the implementation process:

DispatcherServlet represents the front controller and is the control center of the entire SpringMVC. The user makes a request, DispatcherServlet receives the request and intercepts it.

We assume that the URL requested is:

http://localhost:9999/SpringMVC/input-product

The URL above is split into three parts:

(1)http://localhost:9999 Server Domain Name

(2)SpringMVC web site deployed on server (http://localhost:9999)

(3)Input-product indicates controller

Parsing, the url above is represented as: Request input-product controller for Spring MVC site at server localhost:9999

HandlerMapping is the processor mapping. DispatcherServlet calls HandlerMapping,HandlerMapping looks up Handler based on request url

3.HandlerExecution represents a specific Handler, whose main function is to find the controller according to the url. As above, the url is found as: input-product

4. HandlerExecution passes the parsed information to DispatcherServlet, such as parsing controller mapping, etc.

HandlerAdapter represents a handler adapter that executes handlers according to specific rules.

6.Handler lets specific Controller execute

7. Controller returns specific execution information to HandlerAdapter, such as ModelAndView

HandlerAdapter passes view logical name or model to DispatcherServlet

9. DispatcherServlet calls ViewResolver to parse the logical view name passed by HandlerAdapter

10. The view parser passes the parsed logical view name to the DispatcherServlet

11. DispatcherServlet calls a specific view based on the view parsed by the view parser.

12. The final view is presented to the user.

Three SpringMVC core components

(i) DispatcherServlet

DispatcherServlet is the so-called Spring MVC front-end controller, which acts as the control center for the entire Spring MVC, and its related UML is as follows:

2) HandlerMapping

HandlerMapping is mainly used to parse the request url, parse out the controller, and thus map the controller. There are 16 related classes.

The UML diagram for HandlerMapping is as follows

c) HandlerAdapter

HandlerAdapter is mainly a scheduling Controller to handle business logic, etc., and there are 6 related classes.

UML for HandlerAdapter is as follows:

d) ViewResolver

ViewResolver interface is mainly used to parse the logical view name passed by DispatcherServlet and return the parsing result to DispatcherServlet. There are 19 related classes or interfaces that implement this interface.

The main UML for ViewResolver is as follows:

The above is "Spring MVC implementation process sample analysis" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report