重定向是否可以重定向到post接口

不能重定向到post接口,但是可以使用RedirectAttributes.addFlashAttribute模拟post效果

@RequestMapping("/test")
String test(HttpServletResponse response, RedirectAttributes redirectAttributes) throws IOException {
 //......
 redirectAttributes.addFlashAttribute("message","brx");//重定向过去之后,不会在url栏上显示参数,addAttribute会显示
 redirectAttributes.addFlashAttribute("redirectUrl","456");
 //response.sendRedirect("/toPage"); 推荐使用下面方式,这种参数会有问题
 return "redirect:/toPage";


 @GetMapping("/toPage") //POST,会提示不支持GET
 public String toPage(@ModelAttribute("message")String message,
                      @ModelAttribute("redirectUrl")String redirectUrl
 //可以在参数增加Model,查看所有请求数据:model.asMap()
posted @ 2020-09-10 15:23  brx_blog  阅读(2034)  评论(0编辑  收藏  举报