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