Java Spring3Web请求拦截器-如何获得BindingResult?
我真的很欣赏Spring3Anation驱动的Web控制器映射 我有很多控制器的签名如下:Java Spring3Web请求拦截器-如何获得BindingResult?,java,web-applications,spring-mvc,interceptor,Java,Web Applications,Spring Mvc,Interceptor,我真的很欣赏Spring3Anation驱动的Web控制器映射 我有很多控制器的签名如下: @RequestMapping(value = "solicitation/create",method = RequestMethod.POST) public String handleSubmitForm(Model model, @ModelAttribute("solicitation") Solicitation solicitation, BindingResult result) 但
@RequestMapping(value = "solicitation/create",method = RequestMethod.POST)
public String handleSubmitForm(Model model, @ModelAttribute("solicitation") Solicitation solicitation, BindingResult result)
但我的问题是,我想编写一个拦截器,在处理完BindingResults后,它将遍历BindingResults——我如何从HttpRequest或HttpResponse获取它们
因为interpetor方法具有相似的签名
public boolean postHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
执行控制器方法
BindingResult
后,将其存储为名为BindingResult.model\u KEY\u PREFIX+
的模型属性,随后的模型属性将合并到请求属性中。因此,在合并之前,您可以使用Hurda自己的答案,在合并之后使用:
request.getAttribute(BindingResult.MODEL_KEY_PREFIX + "solicitation")
因此,在@Axtavt的大力帮助下,我得出结论,您可以在postHandle方法中从ModelAndView绑定reuslt:
void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
String key = BindingResult.MODEL_KEY_PREFIX + "commandName";
BindingResult br = (BindingResult) modelAndView.getModel().get(key);
}
我在文档中的哪里可以找到这些信息?(我从Spring3.0开始)@Hurda:访问
BindingResult
而不使用标准工具(例如
标签)是一个相当高级的主题,所以在javadoc中描述的模型中放置BindingResult
:所以我刚刚测试了它,BindResult不在请求属性中,而是在模型中。但这没关系,因为ModelAndView是void postHandle的一部分(HttpServletRequest请求、HttpServletResponse响应、对象处理程序、ModelAndView ModelAndView)签名