RedirectAttributes是SpringMVC3.1版本之后出来的一个新功能,专门用于重定向之后还能带参数跳转的的工具类。

两种带参方式:

  • redirectAttributes.addAttributie("prama",value);
  • redirectAttributes.addFlashAttributie("prama",value);

第一种:

redirectAttributes.addAttributie("prama",value);这种方法是在重定向之后在URL后面拼接参数

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在跳到页面后马上移除对象。

这个方法只能在重定向的页面上使用EL表达式取值,

如果是重定向到Controller中是无法获取param中的value,除非在controller中用(@RequestPrama(value = "prama")String prama)注解,采用传参的方式。页面获值例如:

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 }

  

最新文章

  1. LINQ之路 7:子查询、创建策略和数据转换
  2. HDU 1174 爆头(计算几何)
  3. OCJP(1Z0-851) 模拟题分析(六)over
  4. [QGLViewer]First Demo
  5. RabbitMQ(二) -- Work Queues
  6. fiddler对手机进行抓包
  7. Java修饰符关键词大全
  8. C++ cout cerr 和 clog 的区别
  9. 数据结构(主席树):HDU 4729 An Easy Problem for Elfness
  10. 【转】notepad++设置字体和字体大小
  11. JAVA设计模式(09):结构化-代理模式(Proxy)
  12. highlight高亮
  13. windows7旗舰版系统自带组件IIS搭建ftp
  14. HTTP 协议
  15. Chapter 7:Statistical-Model-Based Methods
  16. 关于react-redux中的connect函数
  17. Android 开发笔记___AutoComplateTextView__自动完成文本框
  18. 我认知的javascript之函数调用
  19. Python爬虫【实战篇】百度翻译
  20. Gym - 100637J

热门文章

  1. 【LeetCode】414. Third Maximum Number 解题报告(Python & C++)
  2. 【LeetCode】865. Smallest Subtree with all the Deepest Nodes 解题报告(Python & C++)
  3. java 堆、栈
  4. Probabilistic Principal Component Analysis
  5. [opencv]GeneralProcessing_Template_Function
  6. .NET5.0 依赖注入,关于 Autofac 使用
  7. Hexo博客部署到腾讯云服务器全过程(Nginx,证书,HTTPS),你要的这里都有
  8. django中写入数据时给密码加密
  9. centos7 安装locate
  10. vue中computed的作用以及用法