统一异常处理器
// ...import org.springframework.web.bind.annotation.ControllerAdvice;import org.springframework.web.bind.annotation.ExceptionHandler;import org.springframework.web.bind.annotation.ResponseBody;@ControllerAdvicepublic class GlobalExceptionHandler { /**-------- 通用异常处理方法 --------**/ @ExceptionHandler(Exception.class) @ResponseBody public R error(Exception e) { e.printStackTrace(); return R.fail(e); // 通用异常结果 } /**-------- 指定异常处理方法 --------**/ @ExceptionHandler(NullPointerException.class) @ResponseBody public R error(NullPointerException e) { e.printStackTrace(); return R.fail(ResultCodeEnum.NULL_POINT); } @ExceptionHandler(HttpClientErrorException.class) @ResponseBody public R error(IndexOutOfBoundsException e) { e.printStackTrace(); return R.fail(ResultCodeEnum.HTTP_CLIENT_ERROR); } /**-------- 自定义定异常处理方法 --------**/ @ExceptionHandler(CMSException.class) @ResponseBody public R error(CMSException e) { e.printStackTrace(); return R.fail(e.getMessage()); } /**-------- 自定义定异常处理方法 --------**/ @ExceptionHandler(BizException.class) @ResponseBody public BaseResponse<Void> handler(BizException e) { System.out.println("进入业务异常"+e.getRetCode()+e.getRetMessage()); return R.fail(CodeEnum.ERROR.getMessage()); }}