Spring 3 web请求拦截器 - 我如何获得BindingResult? [英] Spring 3 web request interceptor - how do I get BindingResult?

查看:1383
本文介绍了Spring 3 web请求拦截器 - 我如何获得BindingResult?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很欣赏Spring 3 anoation驱动的Web控制器映射

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) 

但我的问题是,我想编写一个拦截器,通过BindingResults处理后 - 如何从HttpRequest或HttpResponse获取它们?

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?

因为intercpetor方法具有相似的签名

as intercpetor methods are with alike signature

public boolean postHandle(HttpServletRequest request, HttpServletResponse response, Object handler)


推荐答案

所以在@Axtavt的大力帮助下,我开始意识到你可以通过postHandle方法从ModelAndView中获取绑定:

So with big help from @Axtavt I came to conlusion, that you can get to Bind reuslt from ModelAndView in postHandle method:

void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
  String key = BindingResult.MODEL_KEY_PREFIX + "commandName";
  BindingResult br = (BindingResult) modelAndView.getModel().get(key);
}

这篇关于Spring 3 web请求拦截器 - 我如何获得BindingResult?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆