全局异常处理器: Controller抛出的异常没有处理,最终会抛给全局异常处理器处理,处理完后再给浏览器响应统一处理结果集。
@RestControllerAdvice = @ControllerAdvice + @ResponseBody
所以在全局异常处理器中的返回结果还是JSON数据
程序
/*
全局异常处理器
*/
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)//捕获所有异常
public Result ex(Exception ex){
ex.printStackTrace();
return Result.error("对不起,操作失败,请联系管理员");
}
}