您会注意到抛出了异常
ModelAttributeMethodProcessor#resolveArgument(..)。它发生在这里
if (binder.getBindingResult().hasErrors()) { if (isBindExceptionRequired(binder, parameter)) { throw new BindException(binder.getBindingResult()); }}因此,如果解析date参数时发生错误(或其他任何错误)并
isBindExceptionRequest(..)返回true,则将它们
BindingResult包装在中
BindException并引发。那是什么
isBindExceptionRequires(..)?
这样实现
protected boolean isBindExceptionRequired(WebDataBinder binder, MethodParameter parameter) { int i = parameter.getParameterIndex(); Class<?>[] paramTypes = parameter.getMethod().getParameterTypes(); boolean hasBindingResult = (paramTypes.length > (i + 1) && Errors.class.isAssignableFrom(paramTypes[i + 1])); return !hasBindingResult;}和javadoc的说
返回 :
true如果下一个方法参数不是Errors类型。
换句话说,如果这样声明您的处理程序方法
public String submitForm(@Valid @ModelAttribute(MODEL_ATTRIBUTE_STUDENT) StudentDTO edited, BindingResult bindingResult, RedirectAttributes attributes) {一
BindException将不被拆毁因为有类型的参数
Errors(
BindingResult是一个子类型)旁边的
@ModelAttribute参数。
这意味着您正在从其他一些处理程序方法中获取异常,而您没有
BindingResult以下命令对象参数。或者您的配置中还有其他内容没有显示给我们。



