[英]Spring 3 web request interceptor - how do I get BindingResult?
我真的很欣赏Spring 3 anoation驱动的Web控制器映射
我有很多带有签名的控制器:
@RequestMapping(value = "solicitation/create",method = RequestMethod.POST)
public String handleSubmitForm(Model model, @ModelAttribute("solicitation") Solicitation solicitation, BindingResult result)
但我的问题是,我想编写一个拦截器,它会在处理后通过BindingResults - 我如何从HttpRequest或HttpResponse获取它们?
因为intercpetor方法具有相似的签名
public boolean postHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
在执行控制器方法之后, BindingResult
被存储为名为BindingResult.MODEL_KEY_PREFIX + <name of the model attribute>
,稍后的模型属性将合并到请求属性中。 因此,在合并之前,您可以在合并使用后使用Hurda自己的答案:
request.getAttribute(BindingResult.MODEL_KEY_PREFIX + "solicitation")
所以在@Axtavt的大力帮助下,我得到了结论,你可以在postHandle方法中从ModelAndView获取绑定:
void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
String key = BindingResult.MODEL_KEY_PREFIX + "commandName";
BindingResult br = (BindingResult) modelAndView.getModel().get(key);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.