定义一个类 加上@ControllerAdvice注解
@ExceptionHandler加在方法上 用于指定处理什么样的异常
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseBody
public R error(Exception e){
e.printStackTrace();
return R.error().message(e.getMessage());
}
}