10、Spring MVC 之 Flash attributes
来源:互联网 发布:java微信商城开源 编辑:程序博客网 时间:2024/05/29 05:02
Flash attributes提供一种方式给一个request储存attributes用来给另一个请求使用。这是最常见的重定向时所需要的–例如,Post/Redirect/Get
模式。在重定向之前Flash attributes被临时保存(典型是保存在session中)使得它能够在重定向之后对于request可以获取然后立刻被移除。
Spring MVC有2个抽象用来支持flash attributes.FlashMap
用来储存flash attributes,FlashMapManager
用来储存,检索以及管理FlashMap
实例。
Flash attribute通常是”on”状态并且也不需要明确的激活。如果没有被使用,它决不创建HTTP Session.每个请求都有一个”input”的FlashMap
带有从上一个reqeust带过来attribute(if any).并且一个带有attributes的”output”类型的FlashMap
将会为下一个request保存。并且在Spring MVC中FlashMap
实例可以在任何地方都能通过RequestContextUtils
访问到。
带注释的Controller通常不需要直接使用FlashMap
。带有@RequestMapping
方法可以接收RedirectAttributes
类型的参数并且用它来添加flash attributes用于重定向的场景。通过RedirectAttributes
途径添加的Flash attributes可以自动传播给”output”FlashMap
.同样的,在redirect之后,从”input”FlashMap
来的attributes会自动添加到目标URL的Model
中。
Matching requests to flash attributes
在其它Web Frameworks也存在flash attribute这个概念并且已经证明有时候会存在并发问题。因为直到下一个request之前,flash attributes是被储存着的。可是”next”request还没有打算接受,但是 另外一个异步request(轮询或资源请求)导致flash attributes太早被删除。
为了减少这种错误的可能性,RedirectView
自动通过目标重定向URL的path和请求参数来”stamps”(印记)FlashMap
实例。当连接”input”的FlashMap
的时候,FlashMapManager
默认会依次匹配到来的request的信息。
这样不能完全的消除线程安全问题的可能性,但是可以通过重定向URL获取到的信息可以大大降低这种情况。因此使用flash attributes主要被推荐在使用在redirect(重定向)场景。
因为水平有限,翻译不足之处还望见谅。
原文地址:spring-framework-reference-4.2.6.RELEASE
- 10、Spring MVC 之 Flash attributes
- 在Spring MVC 中使用 flash attributes
- Flash Attributes in Spring MVC 3.1
- Understanding Spring MVC Model and Session Attributes
- How to use Session attributes in Spring-mvc
- 待翻译---- Understanding Spring MVC Model and Session Attributes
- Spring MVC Flash 属性解决属性丢失
- spring mvc之handlermapping
- Spring MVC 之 AbstractCommandController
- Spring MVC之MultiActionController
- Spring MVC 之 AbstractCommandController
- Spring MVC之HelloWorld
- Spring之MVC模块
- Spring MVC之MultiActionController
- Spring之MVC模块
- bbs---之spring mvc
- Spring MVC之 HelloWorld
- Spring MVC之 请求
- php-数据库的数据删除
- LeetCode - 3Sum
- 伪目标
- 操作系统一二章作业答案
- 推荐一些好的atom插件
- 10、Spring MVC 之 Flash attributes
- springMVC静态资源访问
- Hdfs杂技
- 设计模式
- hdu 5017 Ellipsoid 模拟退火
- 单片机
- [LeetCode]83. Remove Duplicates from Sorted List
- HBase中正则过滤表达式与JAVA正则表达式不一致问题的分析和解决
- Ubuntu下su:authentication failure的解决办法