我想知道如何在Spring MVC 3.1中重定向后读取flash属性.
我有以下代码:
@Controller
@RequestMapping("/foo")
public class FooController {
@RequestMapping(value = "/bar", method = RequestMethod.GET)
public ModelAndView handleGet(...) {
// I want to see my flash attributes here!
}
@RequestMapping(value = "/bar", method = RequestMethod.POST)
public ModelAndView handlePost(RedirectAttributes redirectAttrs) {
redirectAttrs.addFlashAttributes("some", "thing");
return new ModelAndView().setViewName("redirect:/foo/bar");
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我正在使用Spring MVC,我希望它能从数据库中绑定一个持久对象,但我无法弄清楚如何设置我的代码以在绑定之前调用DB.例如,我正在尝试将"BenefitType"对象更新到数据库,但是,我希望它从数据库中获取对象,而不是创建新对象,因此我不必更新所有字段.
@RequestMapping("/save")
public String save(@ModelAttribute("item") BenefitType benefitType, BindingResult result)
{
...check for errors
...save, etc.
}
Run Code Online (Sandbox Code Playgroud)