spring mvc RedirectAttributes
org.springframework.web.servlet.mvc.support.RedirectAttributes
org.springframework.web.servlet.mvc.support.RedirectAttributes to specify the exact set of attributes to use in case of a redirect and also to add flash attributes (attributes stored temporarily on the server-side to make them available to the request after the redirect). RedirectAttributes is used instead of the implicit model if the method returns a "redirect:" prefixed view name or RedirectView.
该类用来存储指定的属性集合,其中包括重定向的一些属性参数和一些临时属性信息(这些属性存储在服务器的临时空间中,为了使它们在重定向后对于request依然可以使用)。当方法中返回一个"redirect:"前缀的视图名或者重定向视图,RedirectAttributes被用来替代隐含的model属性。
By default all model attributes are considered to be exposed as URI template variables in the redirect URL. Of the remaining attributes those that are primitive types or collections/arrays of primitive types are automatically appended as query parameters.
默认情况下,所有模型属性都被认为是在重定向的URL中暴露URI模版变量的。剩下的那些原始类型属性,或者原始类型的集合或数组属性,自动追加在后面作为查询参数。
In annotated controllers however the model may contain additional attributes originally added for rendering purposes (e.g. drop-down field values). To gain precise control over the attributes used in a redirect scenario, an @RequestMapping method can declare an argument of type RedirectAttributes and use it to add attributes for use in RedirectView. If the controller method does redirect, the content of RedirectAttributes is used. Otherwise the content of the default Model is used.
然而在注解的控制类中,model可能包含最初添加的额外属性以用来提交目的。为了获取精确的控制,通过重定向方案中的属性信息,一个@RequestMapping方法能够声明一个RedirectAttributes类型的参数,并将该属性用在RedirectView中。如果这个控制器重定向了,RedirectAttributes中的内容会被使用。否则使用的是默认model中的内容。
The RequestMappingHandlerAdapter provides a flag called "ignoreDefaultModelOnRedirect" that can be used to indicate the content of the default Model should never be used if a controller method redirects. Instead the controller method should declare an attribute of type RedirectAttributes or if it doesn’t do so no attributes should be passed on to RedirectView. Both the MVC namespace and the MVC Java config keep this flag set to false in order to maintain backwards compatibility. However, for new applications we recommend setting it to true
RequestMappingHandlerAdapter提供了一个标识名为”ignoreDefaultModelOnRedirect",能够用来指明,当一个控制器方法重定向时,默认model中哪些内容内容应该永远不被使用。相反的控制器方法应该声明一个RedirectAttribute属性,或者当它不这么做时,应该没有属性被传递给RedirecView。mvc命名空间和mvcjava配置需要声明这个标识为false,目的是保留向后的兼容性。然而对于新的应用我们推荐设置为true。
The RedirectAttributes interface can also be used to add flash attributes. Unlike other redirect attributes, which end up in the target redirect URL, flash attributes are saved in the HTTP session (and hence do not appear in the URL). The model of the controller serving the target redirect URL automatically receives these flash attributes after which they are removed from the session. See Section 17.6, “Using flash attributes” for an overview of the general support for flash attributes in Spring MVC.
这个RedirectAttributes接口可以被用来添加临时的属性。和那些在目标重定向URL结束的重定向参数不同,临时属性被记载在session中(今后不会在rul中出现)。控制器的model提供了目标重定向地址自动接收这些零时参数,当他们从session中被移除时。17.6章节讲述springmvc如何支持临时属性信息
spring mvc RedirectAttributes的更多相关文章
- Spring MVC RedirectAttributes的用法解决办法
Spring MVC RedirectAttributes的用法很久没发过技术贴了,今天对于一个问题纠结了2小时,遂放弃研究用另一种方法解决,奈何心中一直存在纠结,发帖求解 我先解释下什么是Redir ...
- Spring MVC RedirectAttributes取值方法
RedirectAttributes是Spring mvc 3.1版本之后出来的一个功能,专门用于重定向之后还能带参数跳转的他有两种带参的方式:第一种: attr.addAttribute(" ...
- spring mvc重定向方法
一.不带参数,直接重定向到另一个地址: 返回String直接跳转,如: @RequestMapping(value = "/filehandle") public String u ...
- spring mvc 请求转发和重定向(转)
spring mvc controller间跳转 重定向 传参 url:http://zghbwjl.blog.163.com/blog/static/12033667220137795252845/ ...
- spring mvc controller间跳转 重定向 传参 (转)
转自:http://zghbwjl.blog.163.com/blog/static/12033667220137795252845/ 1. 需求背景 需求:spring MVC框架contr ...
- spring mvc 4.3.2 + mybatis 3.4.1 + mysql 5.7.14 +shiro 幼儿园收费系统 之 登录
如标题,用spring mvc 4.3.2+mybatis 3.4.1 + mysql 5.7.14 +shiro 开发了一个用于幼儿园的管理系统. 功能模块 包括 账号,角色,权限管理. 幼儿档案管 ...
- Spring MVC 学习总结(六)——Spring+Spring MVC+MyBatis框架集成
与SSH(Struts/Spring/Hibernate/)一样,Spring+SpringMVC+MyBatis也有一个简称SSM,Spring实现业务对象管理,Spring MVC负责请求的转发和 ...
- Spring MVC 学习总结(三)——请求处理方法Action详解
Spring MVC中每个控制器中可以定义多个请求处理方法,我们把这种请求处理方法简称为Action,每个请求处理方法可以有多个不同的参数,以及一个多种类型的返回结果. 一.Action参数类型 如果 ...
- Spring MVC 学习总结(二)——控制器定义与@RequestMapping详解
一.控制器定义 控制器提供访问应用程序的行为,通常通过服务接口定义或注解定义两种方法实现. 控制器解析用户的请求并将其转换为一个模型.在Spring MVC中一个控制器可以包含多个Action(动作. ...
随机推荐
- Vue-router路由基础总结(一)
一.安装 npm下载:npm install vue-router 如果在一个模块化工程中使用它,必须要通过 Vue.use() 明确地安装路由功能:在你的文件夹下的 src 文件夹下的 main.j ...
- VMware(bridge、NAT、host-only、custom)含义
摘自: http://www.liangston.com/?post=48 VMware(bridge.NAT.host-only.custom)含义 作者:LiangSton 发布于:2012-1- ...
- .Net Core+Angular Cli/Angular4开发环境搭建教程
一.基础环境配置1.安装VS2017v15.3或以上版本2.安装VSCode最新版本3.安装Node.jsv6.9以上版本4.重置全局npm源,修正为淘宝的NPM镜像:npminstall-gcnpm ...
- mybatis多参数查询
第三种比较好点 http://www.2cto.com/database/201409/338155.html
- android开发笔记之Volley (1)
1. volley的简介 Volley is an HTTP library that makes networking for Android apps easier and most import ...
- java web 拦截器、过滤器理解
1.首先要明确什么是拦截器.什么是过滤器 1.1 什么是拦截器: 拦截器,在AOP(Aspect-Oriented Programming)中用于在某个方法或字段被访问之前,进行拦截然后在之前或之后加 ...
- 接口测试框架开发(二):extentreports报告中文乱码问题
转载:http://www.cnblogs.com/lin-123/p/7146935.html 问题:中文乱码 问题解决:eclipse设置编码为utf-8 结果:
- JMeter 九:给请求加断言
参考:http://jmeter.apache.org/usermanual/component_reference.html#assertions 背景 在测试过程中,我们需要对某个请求的结果进行判 ...
- Linux打包解压
tar tar命令可以用来压缩打包单文件.多个文件.单个目录.多个目录. 常用格式: 单个文件压缩打包: tar czvf my.tar file1 多个文件压缩打包: tar czvf my.tar ...
- Andorid上拉加载更多的几种实现方式
1.前言 Andriod中上拉加载更多的效果随处可见,因为一次性要展现的数据太多信息量太大的话,给用户的体验就很差(加载慢,界面卡顿.流量消耗大等),而加载更多可以控制每次加载条目的数量以达到快速加载 ...