gpt4 book ai didi

当我在 spring mvc 中使用验证时发生 java.lang.annotation.AnnotationFormatError

转载 作者:行者123 更新时间:2023-11-28 01:26:22 24 4
gpt4 key购买 nike

当我使用验证时,我得到 these errors .它发现了错误,但是当我再次返回同一个 jsp 页面时,它抛出了这些异常,否则它会工作。如有任何建议,我们将不胜感激。

最佳答案

发生这种情况是因为您可能在实体中将 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
}

关于当我在 spring mvc 中使用验证时发生 java.lang.annotation.AnnotationFormatError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51222943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com