- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 Spring 很陌生。
我希望验证对 SpringMVC 生命周期的以下理解——将事物放在整体 View 中的位置:
整个过程是请求驱动的。
有一个Front Controller pattern Spring MVC 中的 Front Controller 是 DispatcherServlet .
在用户的每个传入请求时,Spring 都会管理
here 中描述的整个生命周期.
总体来看,DispatcherServlet将请求分派(dispatch)给后端服务的 Controller 。
完成此操作后,它会将其交给 MVC 的 View 组件,以准备其 View 以响应用户。
更详细地说,
最佳答案
让我们一步一步详细介绍
DispatcherServlet uses Handlers to decide "which controller" to serve that request
DispatcherServlet
维持有序
List
的
HandlerMapping
bean(它从
WebApplicationContext
加载)。一个
HandlerMapping
是
Interface to be implemented by objects that define a mapping between requests and handler objects.
DispatcherServlet
接收到一个请求,它会遍历这个列表,直到找到一个匹配的处理程序对象。为简单起见,我们只考虑
RequestMappingHandlerMapping
.
@RequestMapping
的映射。存储为
Method
的带注释的方法(通过反射检索到的实际
HandlerMethod
对象)实例并包装在
RequestMappingInfo
中保存映射数据以匹配请求的对象,即。 URL、 header 和请求参数。
DispatcherServlet
检索最佳匹配
HandlerMethod
从这些和任何相应的
HandlerInterceptor
您可能已经注册的实例。它将这些检索为
HandlerExecutionChain
目的。它将首先应用任何
pre-handling通过
HandlerInterceptor
s。然后它将尝试调用您的
HandlerMethod
.这通常(但不总是)是
@RequestMapping
@Controller
中的注释方法注释类。这会产生 Spring 所称的
调度结果 .
DispatcherServlet
然后申请
post-handling由
HandlerInterceptor
s。它最终根据它是什么来处理调度结果。
You can see the supported return types for an idea of what that can be.
The controllers are/should be "light-weighted"-- should be decoupled from the service processes at back end as a good design practice-- they hold references to the service(s) and invoke the right one(s). Their "mission" is to control the service process(es) for building the model and handing it back to the dispatcher for the next step.
Model
),
DispatcherServlet
可能使 View 可用。我说可能是因为 Controller 可以直接产生响应而不涉及任何 View (想想
jsp
)。
The View component in itself has 2 parts: first the ViewResolver picks the right type of look for View to put the model into the final format for the user.
Model
的典型情况下,
View
,
ModelAndView
,
String
(和其他一些)对象,然后是
ViewResolver
将处理找到正确的
View
.
DispatcherServlet
然后尝试按照您所说的首先合并模型来呈现该 View 。这通常意味着拿走所有
Model
属性并将它们放入
HttpServletRequest
属性。渲染步骤可能涉及渲染
jsp
,生成 XML 或任何东西。
From the developer's angle-- the DispatcherServlet is a behind-the-scenes thing. All i do is to define, and configure it, if necessary, in web.xml. As the developer, I instantiate an ApplicationContext (there are many ApplicationContext types-- i pick one depending on what i need, typically the WebApplicationContext(?) ).
DispatcherServlet
当
ContextLoaderListener
容器电话
Servlet
在上面。它将生成自己的
init()
.
WebApplicationContext
.
AplicationContext is the factory that creates all the servlets/beans including the DispatcherServlet, using their descriptions in the .xml files. The DispatcherServlet then runs behind the scenes and manages the entire process-- goes&gets the controllers, using the annotations or the their .xml descriptions, views, handlers, validators etc.
WebApplicationContext
也称为
控制容器反转 .它不包括
<init-param>
.
ApplicationContext
由
DispatcherServlet
管理容器而不是Spring。但是,它确实主要从 Spring 的
DispatcherServlet
中获取配置。 (
Servlet
)。
What you can do is decide which subclass of ApplicationContext
to use. This is an important choice if you want to load your context from XML or from a Java configuration. You can do this by providing an WebApplicationContext
It registers a number of special beans it finds in the context.
<mvc:annotation-driven>
I am wondering whether this description is holds-- valid&complete, and whether there are big missing pieces in it.
Servlet
Web应用程序。因此,应用程序的生命周期与
Servlet
相关联。容器。
关于spring-mvc - SpringMVC生命周期——全貌,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20385474/
基于SpringBoot版本如下: org.springframework.boot spring-boot-starter-parent 2.5.2
@RestController public class TestController { @GetMapping("/download") public ResponseEntit
概述 记得之前跟前端同事联调接口的时候,后端SpringMVC需要接收数组类型的参数,然后跟前端说需要传数组类型过来。后来前端童鞋传了数组,但是后端接收不成功,联调失败。那时候由于时间关系没有仔细研究
web.xml 片段: contextConfigLocation /WEB-INF/applicationContext-security.xml a
目录 相关准备 功能清单 具体功能:访问首页 ①配置view-controller ②创建页面
Spring mvc是一个非常轻量的mvc框架,注解可以大大减少配置,让请求的拦截变得比较简单。这次记录下@RequestBody 注解接收参数尤其是数组参数的用法。 关于容器的配置不再多说,这里
目录 SpringMVC默认处理的几种异常 @ResponseStatus 异常处理的顺序 自定义异常类(SpringMVC的异常处理)
目录 SpringMVC 接收前端传递的参数四种方式 @RequestParam 获取注解 @PathVariable获取注解 Sp
目录 @PathVariable的用法解析 问题描述 解析过程 动态参数使用@PathVariable
目录 SpringMVC @NotNull校验不生效 加了两个依赖问题解决 @NotNull注解失效原因之一 Lo
springmvc―handlermapping三种映射 handlermapping负责映射中央处理器转发给controller的映射策略,简单说就是控制中央处理器的请求触发哪一个control
目录 使用ModelAndView向request域对象共享数据 使用Model向request域对象共享数据 使用map向request域对象共享数据
整合SSM 环境要求 环境: IDEA MySQL5.7.19 Tomcat9 Maven3.6 要求: 需要熟练掌握MySQL数据库,Spring,Ja
目录 1、SpringMVC简介 2、工作流程与介绍 3、代码截图 以下组件通常使用框架提供实现: 1、Di
简介 SpringMVC的处理器拦截器类似于Servlet开发中的过滤器Filter,用于对处理器进行预处理和后处理。开发者可以自己定义一些拦截器来实现特定的功能。 过滤器
背景 举个例子,出现中文乱码的例子:提交表单的时候。 表单 ?
请求进入DispatcherServlet的doDispatch后,获取HandlerMethod。然后根据HandlerMethod来确认HandlerApapter,确认后执行HandlerAd
实现需求: 1.用户未登录,跳转到登录页,登录完成后会跳到初始访问页。 2.用户自定义处理(如需要激活),跳转到激活页面,激活完成后会跳到初始访问页。 使用到的框架 springmvc 的拦
为了实现用户登录拦截你是否写过如下代码呢? 1. 基于Filter ?
springmvc dao层和service层的区别 首先解释面上意思,service是业务层,dao是数据访问层 这个问题我曾经也有过,记得以前刚学编程的时候,都是在service里直接调用d
我是一名优秀的程序员,十分优秀!