重定向是否可以重定向到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()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM