使用验证时,我得到these errors。它找到错误,但是当我再次返回相同的jsp页面时,它将引发这些异常,否则它将起作用。任何建议,将不胜感激。
答案 0 :(得分:0)
之所以会这样,是因为您可能在实体中将groups
和payload
定义为@NotNull
注释。
您的表单提交没有为此提交任何值,因此null
一直存在,因此您遇到了这些错误。
更好地定义BindingResult并控制以下错误。
@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
}