SpringMVC之RedirectAttributes属性
2024-10-19 21:59:49
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 }
最新文章
- LINQ之路 7:子查询、创建策略和数据转换
- HDU 1174 爆头(计算几何)
- OCJP(1Z0-851) 模拟题分析(六)over
- [QGLViewer]First Demo
- RabbitMQ(二) -- Work Queues
- fiddler对手机进行抓包
- Java修饰符关键词大全
- C++ cout cerr 和 clog 的区别
- 数据结构(主席树):HDU 4729 An Easy Problem for Elfness
- 【转】notepad++设置字体和字体大小
- JAVA设计模式(09):结构化-代理模式(Proxy)
- highlight高亮
- windows7旗舰版系统自带组件IIS搭建ftp
- HTTP 协议
- Chapter 7:Statistical-Model-Based Methods
- 关于react-redux中的connect函数
- Android 开发笔记___AutoComplateTextView__自动完成文本框
- 我认知的javascript之函数调用
- Python爬虫【实战篇】百度翻译
- Gym - 100637J
热门文章
- 【LeetCode】414. Third Maximum Number 解题报告(Python & C++)
- 【LeetCode】865. Smallest Subtree with all the Deepest Nodes 解题报告(Python & C++)
- java 堆、栈
- Probabilistic Principal Component Analysis
- [opencv]GeneralProcessing_Template_Function
- .NET5.0 依赖注入,关于 Autofac 使用
- Hexo博客部署到腾讯云服务器全过程(Nginx,证书,HTTPS),你要的这里都有
- django中写入数据时给密码加密
- centos7 安装locate
- vue中computed的作用以及用法