RedirectAttributes 是Spring mvc 3.1版本之后出来的一个功能,专门用于重定向之后还能带参数跳转的的工具类。他有两种带参的方式:

第一种:

redirectAttributes.addAttributie("prama",value); 这种方法相当于在重定向链接地址追加传递的参数,例如:

 redirectAttributes.addAttributie("prama1",value1);

 redirectAttributes.addAttributie("prama2",value2);

 return:"redirect:/path/list" ;

以上重定向的方法等同于 return:"redirect:/path/list?prama1=value1&prama2=value2 " ,注意这种方法直接将传递的参数暴露在链接地址上,非常的不安全,慎用。

第二种:

redirectAttributes.addFlashAttributie("prama",value); 这种方法是隐藏了参数,链接地址上不直接暴露,但是能且只能在重定向的 页面获取prama参数值。其原理就是放到session中,session在跳到页面后马上移除对象。如果是重定向一个controller中是获取不到该prama属性值的。除非在controller中用(@RequestPrama(value = "prama")String prama)注解,采用传参的方式。页面获值例如:

 redirectAttributes.addFlashAttributie("prama1",value1);

 redirectAttributes.addFlashAttributie("prama2",value2);

 return:"redirect:/path/list.jsp";

在以上参数均可在list.jsp页面使用EL表达式获取到参数值${prama*}

controller获得redirectAttributes重定向的值例如:

 redirectAttributes.addFlashAttributie("prama1",value1);

 redirectAttributes.addFlashAttributie("prama2",value2);

 return:"redirect:/path/list/"

 @RequestMapping("list")
public List<Student> list(@RequestPrama(value = "prama1")String prama1,
@RequestPrama(value = "prama2")String prama2,...
){
//TODO
//your code }

  通过在controller中的list方法体中可以获取到参数值。

 
 
 
 

Spring中RedirectAttributes的用法的更多相关文章

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

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

  2. 框架源码系列十:Spring AOP(AOP的核心概念回顾、Spring中AOP的用法、Spring AOP 源码学习)

    一.AOP的核心概念回顾 https://docs.spring.io/spring/docs/5.1.3.RELEASE/spring-framework-reference/core.html#a ...

  3. Spring中@Cacheable的用法

    在Spring中通过获取MemCachedClient来实现与memcached服务器进行数据读取的方式.不过,在实际开发中,我们往往是通过Spring的@Cacheable来实现数据的缓存的,所以, ...

  4. Spring中RedirectAttributes对象重定向传参

    Spring3中的FlashAttribute 为 了防止用户刷新重复提交,save操作之后一般会redirect到另一个页面,同时带点操作成功的提示信息.因为是Redirect,Request里 的 ...

  5. Spring中HibernateCallback的用法(转)

    Hibernate的复杂用法HibernateCallback HibernateTemplate还提供一种更加灵活的方式来操作数据库,通过这种方式可以完全使用Hibernate的操作方式.Hiber ...

  6. Spring中jdbcTemplate的用法实例

    一.首先配置JdbcTemplate: 要使用Jdbctemplate 对象来完成jdbc 操作.通常情况下,有三种种方式得到JdbcTemplate 对象.       第一种方式:我们可以在自己定 ...

  7. Spring 中classPath:用法

    参考文章地址: http://hi.baidu.com/huahua035/item/ac8a27a994b55bad29ce9d39 http://blog.csdn.net/lushuaiyin/ ...

  8. spring 中StoredProcedure的用法--转载

    StoredProcedure是一个抽象类,必须写一个子类来继承它,这个类是用来简化JDBCTemplate执行存储过程操作的. 首先我们写一个实现类: package com.huaye.frame ...

  9. Spring中ApplicationContextAware的用法

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt379 一.这个接口有什么用? 当一个类实现了这个接口(Application ...

随机推荐

  1. MyBatis动态SQL之一使用 if 标签和 choose标签

    bootstrap react https://segmentfault.com/a/1190000010383464 xml 中 < 转义 to thi tha <if test=&qu ...

  2. TCP Health Checks

    This chapter describes how to configure health checks for TCP. Introduction NGINX and NGINX Plus can ...

  3. Java中String对象两种赋值方式的区别

    本文修改于:https://www.zhihu.com/question/29884421/answer/113785601 前言:在java中,String有两种赋值方式,第一种是通过“字面量”赋值 ...

  4. Django 中的 日志处理

    日志处理: 上线后必须使用 便于以后的 维护 管理 根据日志 处理 BUG 在 项目中 定义一个 存放日志的 文件夹 log 存放所有 等级 的 日志 配置: 将下面的日志的 配置 写入 django ...

  5. @RequestParam 和@RequestBody 的区别?

    @RequestParam用来接收: 1 用来处理简单的参数绑定 2 用来接收 Content-Type 是   application/x-www-form-urlencoded (这种格 式的数据 ...

  6. pom文件miss artifact com.sun:tools:jar:1.5.0:system问题

    问题现象: 导入新的maven项目时,有时候pom.xml文件会提示一个错误信息:Missing artifact com.sun:tools:jar:1.5.0:system 问题原因: maven ...

  7. [HEOI2016/TJOI2016]字符串

    嘟嘟嘟 今天复习一下SAM. lcp固然不好做,干脆直接翻过来变成后缀.首先答案一定满足单调性,所以我们二分lcp的长度\(mid\),然后判断\(s[d \ldots d + mid - 1]\)是 ...

  8. pytorch torchvision.ImageFolder的使用

    参考:https://pytorch-cn.readthedocs.io/zh/latest/torchvision/torchvision-datasets/ torchvision.dataset ...

  9. 一步一步和我学Apache JMeter

    一. Apache JMeter介绍 1. Apache JMeter是什么? Apache JMeter 是Apache组织的开放源代码项目,是一个100%纯Java桌面应用,用于压力测试和性能测量 ...

  10. python3 迭代器

    ''' 迭代:重复的过程,并且每次迭代的结果都是下次迭代的初始值 可迭代的 Iterable 迭代器 Iterator iter(数据) == 数据.__iter__() 将数据转换为迭代器 next ...