RedirectView
始终用作 GET
请求,但我的应用程序中有多个要求使用 POST
并隐藏 URL 中的参数。
除了
RedirectView
还有其他选择吗?
这是我解决这个问题的方法:
@RequestMapping(value = "/redirectTo", method = { RequestMethod.POST, RequestMethod.GET })
public ModelAndView navigate(HttpServletRequest req, HttpServletResponse resp, @RequestParam String url,
@RequestBody final String body, final RedirectAttributes redirectAttributes) throws Exception {
String redirectUrl = "someUrl";
RedirectView redirectView = new RedirectView();
redirectView.setUrl(redirectUrl);
redirectView.setStatusCode(HttpStatus.TEMPORARY_REDIRECT);
redirectView.setHttp10Compatible(Boolean.TRUE);
return new ModelAndView(redirectView);
}