在Spring MVC 中使用 flash attributes
来源:互联网 发布:php public final 编辑:程序博客网 时间:2024/05/22 04:44
http://www.yulezhandian.com/?p=150
Spring MVC 学习(六) Using flash attributes
17.6 在Spring MVC 中使用 flash attributes
Spring MVC Flash attributes 提供了一个请求存储属性可供另外请求使用一种方式。 在使用重定向时候非常必要 — 例如, Post/Redirect/Get 模式。 Flash attributes 在重定向之前暂存 (就像存在 session中) 以便重定向之后还能使用,并立即删除。
Spring MVC 有两个主要的抽象来支持 flash attributes。 FlashMap
用于保持 flash attributes 而 FlashMapManager
用于存储,检索,管理FlashMap
实例。
Flash attribute 支持默认开启( “on”)并不需要显式启用,它永远不会导致HTTP Session的创建。 每一个请求都有一个 “input”FlashMap
具有从上一个请求(如果有的话)传过来的属性和一个 “output” FlashMap
具有将要在后续请求中保存的属性。 这两个 FlashMap
实例都可以通过静态方法RequestContextUtils从Spring MVC的任何位置访问。
使用注解的控制器通常不需要直接与 FlashMap
一起工作。 相反, @RequestMapping
方法可以接受一个 RedirectAttributes
类型的参数,用它来在重定向场景中增加 flash attributes 。通过RedirectAttributes
加入的 Flash attributes 将自动传播到 “output” FlashMap。同样的,重定向之后,从 “input” FlashMap
来的属性自动添加到控制器的 Model
,为目标URL服务。
Matching requests to flash attributes
闪存属性(flash attributes)的概念存在于许多其他的 Web 框架,事实证明,有时受到并发问题。 这是因为根据定义 flash 属性是要被存储直到下一个请求。但是恰好 "next" 请求并不是接受者,而是另外的异步请求 (例如 轮询或资源请求) 这种情况下,flash attributes 被过早移除。为了减少这种问题的可能性,RedirectView
自动以重定向URL的目标path和query parameters "stamps"FlashMap
实例。 反过来,当查找"input"FlashMap
时, 默认的FlashMapManager
匹配该信息到传入的请求。这并不能完全排除一个并发问题的可能性但尽管如此已在重定向 URL 中可用信息中大大降低。 因此使用闪存属性主要用于重定向场景。
- 在Spring MVC 中使用 flash attributes
- Flash Attributes in Spring MVC 3.1
- 10、Spring MVC 之 Flash attributes
- 在Spring MVC中使用FileUpload功能
- 在Spring MVC中使用FileUpload功能
- 在Spring MVC中使用Velocity
- 在spring-mvc中使用json配置
- 在spring MVC中使用RestTemplate
- 在 spring mvc 中使用 swagger2
- Understanding Spring MVC Model and Session Attributes
- 关于在datagridTag中使用attributes的说明
- 简简单单-在Spring MVC中使用FileUpload功能
- 在Spring-MVC中使用logback和slf4j
- 在Spring MVC中使用Apache Shiro安全框架
- 在Spring MVC中使用Apache Shiro安全框架
- 在spring-mvc中使用swagger2遇到的问题汇总
- 【spring mvc】Spring MVC配置过滤器并在过滤器中使用bean
- 在 Spring MVC + Spring 项目中使用 Spring Security 4.2.3
- 你是码农 还是优秀程序员?
- iOS UITableView中点击状态栏无法回滚到顶部
- 亲们,天冷了记得保暖哦
- maven 多web项目合并war
- 从Windows角度看Mac OS X上的软件开发
- 在Spring MVC 中使用 flash attributes
- ListAcitivity、GridtAcitivity的Adapter中getView()四种优化方案
- 资源博客
- java中数据类型转换
- SD卡工具类
- ecshop订单中只要有一个是包邮商品,就整个订单都包邮
- Gradle的安装使用
- openvpn简介
- ION基本概念介绍和原理分析