我在Spring MVC中使用验证时发生java.lang.annotation.AnnotationFormatError发生

时间:2018-07-07 11:50:46

标签: java html css spring spring-mvc

使用验证时,我得到these errors。它找到错误,但是当我再次返回相同的jsp页面时,它将引发这些异常,否则它将起作用。任何建议,将不胜感激。

1 个答案:

答案 0 :(得分:0)

之所以会这样,是因为您可能在实体中将groupspayload定义为@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
}