当我使用验证时,我收到这些错误。它找到了错误,但是当我再次返回到同一个jsp页面时,它会抛出这些异常,否则它可以工作。任何建议将不胜感激。
发生这种情况是因为您可能已将groups
和payload
定义为实体中的@NotNull
注释。
而且您的表单提交没有为此提交任何值,因此它会null
,因此您会收到这些错误。
最好定义绑定结果并控制如下错误。
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String create(@Valid EntityPojo entity, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
return getPath() + "/update"; //here you return the same page with errors
}
//here you proceed further if there is no error
}