【发布时间】:2014-01-02 07:33:49
【问题描述】:
为了在redirected方法中访问redirect属性,我们利用模型的map,如下所示:
@Controller
@RequestMapping("/foo")
public class FooController {
@RequestMapping(value = "/bar", method = RequestMethod.GET)
public ModelAndView handleGet(Model map) {
String some = (String) map.asMap().get("some");
}
@RequestMapping(value = "/bar", method = RequestMethod.POST)
public ModelAndView handlePost(RedirectAttributes redirectAttrs) {
redirectAttrs.addFlashAttributes("some", "thing");
return new ModelAndView().setViewName("redirect:/foo/bar");
}
}
但是,为什么我们不能以这种方式访问它们:
@RequestMapping(value = "/bar", method = RequestMethod.GET)
public ModelAndView handleGet(RedirectAttributes redAttr) {
String some = redAttr.getFlashAttributes().get("some");
}
如果添加 flashAttributes 的唯一目的是它们在重定向方法中可供模型使用,那么 getFlashAttributes() 的目的是什么?
【问题讨论】: