不能重定向到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()