controller代码
@RequestMapping("") public String index(@Valid User user , BindingResult bindingResult){ if (bindingResult.hasErrors()){ List<ObjectError> allErrors = bindingResult.getAllErrors(); ObjectError objectError = allErrors.get(0); System.out.println(objectError.getDefaultMessage()); System.out.println(objectError.getObjectName()); System.out.println(allErrors); } return "index"; }
请求先来到DispatcherServlet的doDispatch 方法,最终会调用ModelAttributeMethodProcessor#resolveArgument方法
调用DataBinder#validate方法后调用ConstraintTree#validateSingleConstraint,由它来调用具体的验证器
具体的验证器