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