关于重定向RedirectAttributes的用法
来源:互联网 发布:python遍历一个字符串 编辑:程序博客网 时间:2024/05/27 12:22
刚才做项目的时候看到一篇写的很不错的博客,解决我之前对于RedirectAttributes的困惑,也给大家推荐下~
原文地址https://zhuanlan.zhihu.com/p/21353217?refer=pengsong-java
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方法体中可以获取到参数值。
- 关于重定向RedirectAttributes的用法
- 关于重定向RedirectAttributes的用法
- springmvc重定向RedirectAttributes的用法
- SpringMVC重定向RedirectAttributes的使用
- SpringMVC 重定向参数 RedirectAttributes
- SpringMVC 重定向参数 RedirectAttributes
- SpringMVC 重定向参数 RedirectAttributes
- springMVC 请求转发和重定向(RedirectAttributes)
- springmvc之RedirectAttributes重定向带参数设置
- spring mvc RedirectAttributes 重定向 + redis缓存
- 关于页面的重定向的几个用法
- Spring中RedirectAttributes的用法
- Spring MVC RedirectAttributes的用法
- SpringMVC中RedirectAttributes对象重定向传参
- Spring中RedirectAttributes对象重定向传参
- Spring中RedirectAttributes对象重定向传参
- springmvc controller间跳转 重定向传参RedirectAttributes
- Spring中RedirectAttributes对象重定向传参
- 斯坦福大学第七讲-最优间隔分类器
- sdut 3893 Return of the Nim(matrix nim)
- Android常见的几种移动支付
- java 服务器接口快速开发之servlet详细教程
- 【数据结构实验四】数组
- 关于重定向RedirectAttributes的用法
- mongodb 模糊查询
- 自用fake库,生成身份证,手机号,中文姓名,ip地址和邮箱地址等
- 面试笔试(一):平衡二叉树,Java正则验证,List查找时间复杂度,ORM框架的选择
- jQuery选择器优化问题,使用$('#a .b')等,IDE会提示这是低效的用法的解决
- Problem D: 平面上的点和线——Point类、Line类 (V)
- ofo创始人戴威称共享单车日收入接近1000万
- TextInput组件和Touchable组件
- laravel5 数据库配置(MySQL)