Spring 3 Web 请求拦截器 - 如何获取 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 获取它们?
因为拦截器方法具有相似的签名
public boolean postHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
I realy appreciate Spring 3 anoation driven mapping of Web Controllers
I have a lot of Controllers with signatures like:
@RequestMapping(value = "solicitation/create",method = RequestMethod.POST)
public String handleSubmitForm(Model model, @ModelAttribute("solicitation") Solicitation solicitation, BindingResult result)
But my issue is, that I want to write an interceptor that would ho through BindingResults after processing - how do I get them from HttpRequest or HttpResponse?
as intercpetor methods are with alike signature
public boolean postHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
执行控制器方法
BindingResult
后,将其存储为名为BindingResult.MODEL_KEY_PREFIX +
的模型属性,后续模型属性将合并到请求属性中。因此,在合并之前您可以使用 Hurda 自己的答案,合并之后使用:After execution of controller method
BindingResult
is stored as a model attribute namedBindingResult.MODEL_KEY_PREFIX + <name of the model attribute>
, later model attributes are merged into request attributes. So, before merging you can use Hurda's own answer, after merging use:因此,在 @Axtavt 的大力帮助下,我得出结论,您可以在 postHandle 方法中从 ModelAndView 获取 Bind reuslt :
So with big help from @Axtavt I came to conlusion, that you can get to Bind reuslt from ModelAndView in postHandle method: