当前位置:网站首页>重定向设置参数-RedirectAttributes
重定向设置参数-RedirectAttributes
2022-06-13 02:19:00 【liangjiayy】
基本使用:
@RequestMapping(value = "/accounts", method = RequestMethod.POST)
public String handle(Account account, BindingResult result, RedirectAttributes redirectAttrs) {
if (result.hasErrors()) {
return "accounts/new";
}
// 重定向设置属性
redirectAttrs.addAttribute("id", account.getId()).addFlashAttribute("message", "Account created!");
return "redirect:/accounts/{id}";
}
有两种方式:(一般使用addFlashAttribute
,另一种数据在地址栏,用户可见,不安全)
addAttribute
:重定向后在url后面拼上参数;本质上是根据您的属性构造请求参数,然后使用请求参数重定向到所需的页面,即:key1=val1&key2=val2…
使用:// 不转为json,报错:Cannot convert value of type 'java.util.HashMap' to required type 'java.lang.String' Map<String,String> val=new HashMap<>(); ... redirectAttributes.addAttribute("key", JSONObject.toJSONString(val));
addFlashAttribute
:放在session中,第一次使用后将删除
使用Map<String,String> val=new HashMap<>(); ... redirectAttributes.addFlashAttribute("key", val);
边栏推荐
- [work notes] the problem of high leakage current in standby mode of dw7888 motor driver chip
- C language volatile learning
- CCF 201409-1: adjacent number pairs (100 points + problem solving ideas)
- js获取元素
- [learning notes] xr872 GUI littlevgl 8.0 migration (display part)
- Chapter7-10_ Deep Learning for Question Answering (1/2)
- 传感器:SHT30温湿度传感器检测环境温湿度实验(底部附代码)
- In addition to the full screen without holes under the screen, the Red Devils 7 series also has these black technologies
- Yovo3 and yovo3 tiny structure diagram
- Leetcode 93 recovery IP address
猜你喜欢
Mac使用Docker安装Oracle
Jump model between mirrors
[pytorch] kaggle image classification competition arcface + bounding box code learning
Understand CRF
Area of basic exercise circle ※
Ruixing coffee 2022, extricating itself from difficulties and ushering in a smooth path
[programming idea] communication interface of data transmission and decoupling design of communication protocol
Application circuit and understanding of BAT54C as power supply protection
SQLserver2008 拒绝了对对象 '****' (数据库 '****',架构 'dbo')的 SELECT 权限
Huawei equipment is configured with CE dual attribution
随机推荐
Looking at Qianxin's "wild prospect" of network security from the 2021 annual performance report
Huawei equipment is configured with CE dual attribution
柏瑞凱電子沖刺科創板:擬募資3.6億 汪斌華夫婦為大股東
Think: when do I need to disable mmu/i-cache/d-cache?
Paper reading - joint beat and downbeat tracking with recurrent neural networks
SWD debugging mode of stm32
Armv8-m learning notes - getting started
Fast Color Segementation
Share three stories about CMDB
Paper reading - beat tracking by dynamic programming
[pytorch]fixmatch code explanation (super detailed)
【Unity】打包WebGL项目遇到的问题及解决记录
Thesis reading - autovc: zero shot voice style transfer with only autoencoder loss
Chapter7-10_ Deep Learning for Question Answering (1/2)
Mbedtls migration experience
1、 Set up Django automation platform (realize one click SQL execution)
How to do Internet for small enterprises
[pytorch]fixmatch code explanation - data loading
反爬虫策略(ip代理、设置随机休眠时间、哔哩哔哩视频信息爬取、真实URL的获取、特殊字符的处理、时间戳的处理、多线程处理)
Chapter7-13_ Dialogue State Tracking (as Question Answering)