Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望对@valid() 注解的校验异常进行异常捕获处理,给前端用户友好提示。 #7702

Open
shaoweijin opened this issue Jan 9, 2025 · 1 comment

Comments

@shaoweijin
Copy link

版本号:

3.7.1

问题描述:

JeecgBootExceptionHandler.java 类中未看到有对@Valid() 注解的校验异常进行异常捕获处理,导致前端异常把后端java的包名等信息展示出来。
建议在此类中增加如下方法

@ExceptionHandler(MethodArgumentNotValidException.class)
public Result<?> handleValidationExceptions(MethodArgumentNotValidException exception) {
    addSysLog(exception);
    return Result.error("校验失败!" + exception.getBindingResult().getAllErrors().stream().map(ObjectError::getDefaultMessage).collect(Collectors.joining(",")));
}
错误截图:

image

友情提示:

  • 未按格式要求发帖、描述过于简单的,会被直接删掉;
  • 描述问题请图文并茂,方便我们理解并快速定位问题;
  • 如果使用的不是master,请说明你使用的分支;
@zhangdaiscott
Copy link
Member

cr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants