简介:
处理异常返回信息
一、创建 ExceptionAdaptController 类
在web模块里面创建 ExceptionAdaptController类
@RestControllerAdvice public class ExceptionAdaptController { @ExceptionHandler({RuntimeException.class}) public Result runTimeException(RuntimeException exception){ exception.printStackTrace(); return Result.fail(); } @ExceptionHandler({Exception.class}) public Result exception(Exception exception){ exception.printStackTrace(); return Result.fail(); } }
二、创造异常
在接口里 添加 int i= 1/0;
int i =1/0;