springboot|springboot 如何重定向redirect 并隐藏参数
目录
- springboot 重定向redirect 并隐藏参数
- 1、全局异常处理方法
- 2、重定向方法
- springboot redirect 传参问题
- 具体案例
springboot 重定向redirect 并隐藏参数 在做全局异常处理的时候,碰到重定向到全局错误页面
所谓隐藏参数无非是把参数放到了session中,再重定向后将该值清除
1、全局异常处理方法
@ExceptionHandler(value = https://www.it610.com/article/Exception.class)public ModelAndView exceptionHandle(RedirectAttributes redirectAttributes) {ModelAndView modelAndView = new ModelAndView("redirect:/systemError"); redirectAttributes.addFlashAttribute("error", "错误信息"); return modelAndView; }
【springboot|springboot 如何重定向redirect 并隐藏参数】
2、重定向方法
@GetMapping("/systemError")public ModelAndView systemError(@ModelAttribute("error") String error){ModelAndView modelAndView = new ModelAndView("error"); modelAndView.addObject("error", error); return modelAndView; }
springboot redirect 传参问题 众所周知:
redirect表示重定向,相比于请求转发,无法将添加的参数继续保留,传递给下一个处理对象,但springboot给我们提供了一个方法,redirectattributes的addflashattribute方法将参数,即使通过重定向也能传递出去,底层原理使用的是缓存临时保存 重定向所携带的参数
具体案例
controller
文章图片
前端
文章图片
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
推荐阅读
- 考研英语阅读终极解决方案——阅读理解如何巧拿高分
- 如何寻找情感问答App的分析切入点
- Activiti(一)SpringBoot2集成Activiti6
- mybatisplus如何在xml的连表查询中使用queryWrapper
- MybatisPlus使用queryWrapper如何实现复杂查询
- SpringBoot调用公共模块的自定义注解失效的解决
- 解决SpringBoot引用别的模块无法注入的问题
- 如何在Mac中的文件选择框中打开系统隐藏文件夹
- 漫画初学者如何学习漫画背景的透视画法(这篇教程请收藏好了!)
- java中如何实现重建二叉树