@Slf4j
@RestControllerAdvice(basePackages = "指定需要统一处理异常的类所在包路劲")
public class HandleExceptionAdvice {
//ExceptionHandler:此方法捕获的异常类型
@ExceptionHandler(value = MethodArgumentNotValidException.class)
public R handleValidException(MethodArgumentNotValidException e) {
log.error("数据校验错误-> {},错误类型-> {}", e.getMessage(), e.getClass());
return R.error();
}
@ExceptionHandler(Throwable.class)
public R handleAllException(Throwable e) {
log.error("系统未知异常。异常信息-> {},异常类型-> {}", e.getMessage(), e.getClass());
return R.error();
}
}
还没有评论,来说两句吧...