In this example, I don’t understand what the BindingResult is for and what it means to say if (binding.hasErrors()) below.
@RequestMapping(value = "/test", method = RequestMethod.POST)
public final String submit(@ModelAttribute(TEST) @Valid final Test test, final BindingResult binding,
final HttpServletRequest request, final ModelMap modelMap)
{
if (binding.hasErrors())
{
return "test";
}
BindingResultis a data binding result associated with the previous argument (that is,test). It holds information about the errors of binding request parameters to the properties oftest, such as type mismatches. When@Validannotation is present, it also holds errors produced by the authomatic validation oftest.So,
binding.hasErrors()determines whether errors was found during binding and validation of thetest. When such errors present, the typical behaviour is to redisplay the form with errors messages.