【发布时间】:2015-07-04 20:41:28
【问题描述】:
我正在编写一个接受用户注册请求的简单控制器我想验证模型属性,但收到 400 错误请求。 我检查了this question here,这几乎是我遇到的问题,但解决方案对我不起作用。
@RequestMapping(method = RequestMethod.POST, value = "/sign-up", consumes = "application/x-www-form-urlencoded")
public ModelAndView addUser(ModelMap model,@Valid @ModelAttribute
UserRegistrationInfo userRegistrationInfo,
HttpServletRequest httpRequest,
HttpSession httpSession,
BindingResult result) { ..... }
编辑
春季版:4.0.6.RELEASE
看过SpringMVC架构,在DefaultHandlerExceptionResolverclass,doResolveException方法处设置断点,发现抛出了BindException异常。但是不知道为什么BindingResult没有填充,没有调用方法执行让我确定我想要什么行为?执行以返回 handleBindException((BindException) ex, request, response, handler); 结束,即
protected ModelAndView handleBindException(BindException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return new ModelAndView(); }
【问题讨论】:
-
请附上堆栈跟踪或日志!!
-
嗯,这是我第一次尝试看,但到目前为止没有任何可疑之处
-
没有日志到目前为止我找不到任何东西......它在没有任何日志的情况下优雅地返回
-
UserRegistrationInfo 是什么样的?它有无参数构造函数吗?
-
是的,它实际上有一个setter和getter
标签: spring validation spring-mvc