在common模块的pom文件中添加依赖

在MemberRegisterReg类中添加注解

MemberController中添加注解

新增自定义异常
/**
* 校验异常统一处理
* @param e
* @return
*/
@ExceptionHandler(value = BindException.class)
@ResponseBody
public CommonResp exceptionHandler(BindException e) {
CommonResp commonResp = new CommonResp();
LOG.error("业务异常:{}", e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
commonResp.setSuccess(false);
commonResp.setMessage(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
return commonResp;
}
将代码提交到git仓库
本文介绍了如何在SpringMVC项目中,通过添加依赖、类注解以及自定义异常处理器来统一管理业务异常,并将代码提交到git仓库。重点展示了如何使用`@ExceptionHandler`注解处理`BindException`。

被折叠的 条评论
为什么被折叠?



