全局异常处理器

定义一个全局异常处理器

1
2
3
4
5
6
7
8
9
@RestControllerAdvice //@RestControllerAdvice = @ControllerAdvice + @ResponseBody
public class GlobalExceptionHandler {

@ExceptionHandler(Exception.class) // 指定处理那些异常
public Result ex(Exception ex){
ex.printStackTrace();
return Result.error("对不起,操作失败,请联系管理员");
}
}