使用
Model,它应该预先填充Flash属性:
@RequestMapping(value = "/bar", method = RequestMethod.GET)public ModelAndView handleGet(Model model) { String some = (String) model.asMap().get("some"); // do the job}或者,您也可以使用
RequestContextUtils#getInputFlashMap:
@RequestMapping(value = "/bar", method = RequestMethod.GET)public ModelAndView handleGet(HttpServletRequest request) { Map<String, ?> inputFlashMap = RequestContextUtils.getInputFlashMap(request); if (inputFlashMap != null) { String some = (String) inputFlashMap.get("some"); // do the job }}PS你可以做回
return new ModelAndView("redirect:/foo/bar");在handlePost。
编辑 :
JavaDoc说:
调用该方法时,RedirectAttributes模型为空,除非该方法返回重定向视图名称或RedirectView,否则永远不要使用它。
它没有提到
ModelAndView,所以也许将handlePost更改为返回
"redirect:/foo/bar"字符串或
RedirectView:
@RequestMapping(value = "/bar", method = RequestMethod.POST)public RedirectView handlePost(RedirectAttributes redirectAttrs) { redirectAttrs.addFlashAttributes("some", "thing"); return new RedirectView("/foo/bar", true);}我
RedirectAttributes在我的代码中使用
RedirectView和
model.asMap()方法,效果很好。



