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的更多相关文章

  1. Spring MVC RedirectAttributes的用法解决办法

    Spring MVC RedirectAttributes的用法很久没发过技术贴了,今天对于一个问题纠结了2小时,遂放弃研究用另一种方法解决,奈何心中一直存在纠结,发帖求解 我先解释下什么是Redir ...

  2. Spring MVC RedirectAttributes取值方法

    RedirectAttributes是Spring mvc 3.1版本之后出来的一个功能,专门用于重定向之后还能带参数跳转的他有两种带参的方式:第一种: attr.addAttribute(" ...

  3. spring mvc重定向方法

    一.不带参数,直接重定向到另一个地址: 返回String直接跳转,如: @RequestMapping(value = "/filehandle") public String u ...

  4. spring mvc 请求转发和重定向(转)

    spring mvc controller间跳转 重定向 传参 url:http://zghbwjl.blog.163.com/blog/static/12033667220137795252845/ ...

  5. spring mvc controller间跳转 重定向 传参 (转)

    转自:http://zghbwjl.blog.163.com/blog/static/12033667220137795252845/ 1. 需求背景     需求:spring MVC框架contr ...

  6. 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 开发了一个用于幼儿园的管理系统. 功能模块 包括 账号,角色,权限管理. 幼儿档案管 ...

  7. Spring MVC 学习总结(六)——Spring+Spring MVC+MyBatis框架集成

    与SSH(Struts/Spring/Hibernate/)一样,Spring+SpringMVC+MyBatis也有一个简称SSM,Spring实现业务对象管理,Spring MVC负责请求的转发和 ...

  8. Spring MVC 学习总结(三)——请求处理方法Action详解

    Spring MVC中每个控制器中可以定义多个请求处理方法,我们把这种请求处理方法简称为Action,每个请求处理方法可以有多个不同的参数,以及一个多种类型的返回结果. 一.Action参数类型 如果 ...

  9. Spring MVC 学习总结(二)——控制器定义与@RequestMapping详解

    一.控制器定义 控制器提供访问应用程序的行为,通常通过服务接口定义或注解定义两种方法实现. 控制器解析用户的请求并将其转换为一个模型.在Spring MVC中一个控制器可以包含多个Action(动作. ...

随机推荐

  1. reconstruct-original-digits-from-english(好)

    https://leetcode.com/problems/reconstruct-original-digits-from-english/ //https://discuss.leetcode.c ...

  2. 搭建开源入侵检测系统Snort并实现与防火墙联动

    Snort作为一款优秀的开源主机入侵检测系统,在windows和Linux平台上均可安装运行.BT5作为曾经的一款经典的渗透神器,基于 Ubuntu,里面已经预装很多的应用,比如Mysql.Apach ...

  3. Dev之ribbon设置

  4. [Python爬虫] 之二十九:Selenium +phantomjs 利用 pyquery抓取节目信息信息

    一.介绍 本例子用Selenium +phantomjs爬取节目(http://tv.cctv.com/epg/index.shtml?date=2018-03-25)的信息 二.网站信息 三.数据抓 ...

  5. [Android Pro] 注册 Google Play 开发者帐户

    官网地址: https://support.google.com/googleplay/android-developer/answer/6112435?hl=zh-Hans 博客地址: http:/ ...

  6. animateBackground-plugin

    (function ($) { if (!document.defaultView || !document.defaultView.getComputedStyle) { var oldCurCSS ...

  7. CentOS7 Failed to start LSB: Bring up/down networking. 已解决!!!

    服务器更换了主板之前配置的静态IP发现启动网卡出现异常. 执行 service network restart 出现以下错误 Restarting network (via systemctl):  ...

  8. JAVA基础(9)——容器(3)——并发容器

    转载:http://blog.csdn.net/weitry/article/details/52964509 JAVA基础系列规划: JAVA基础(1)——基本概念 JAVA基础(2)——数据类型 ...

  9. ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value:

    今天碰到一个相当棘手的问题,那就是ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value . 本来在本地测试是没有任 ...

  10. 算法笔记_101:蓝桥杯练习 算法提高 身份证号码升级(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 从1999年10月1日开始,公民身份证号码由15位数字增至18位.(18位身份证号码简介).升级方法为: 1.把15位身份证号码中的年份由 ...