zoukankan      html  css  js  c++  java
  • 自定义异常类

    /**
    * 自定制异常类
    *
    * @author MoCha
    * @date 2019/5/25
    */
    @Getter
    public class CustomException extends RuntimeException {
    private int code;
    private String message;

    public CustomException(int code, String message) {
    this.code = code;
    this.message = message;
    }

    public CustomException(ResultStatusEnum resultStatusEnum) {
    this.code = resultStatusEnum.getCode();
    this.message = resultStatusEnum.getMessage();
    }
    }

    /**
    * 全局异常处理
    *
    * @author MoCha
    * @date 2019/5/25
    */
    @ControllerAdvice
    public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(CustomException.class)
    public Map<String, Object> handleCustomException(CustomException customException) {
    Map<String, Object> errorResultMap = new HashMap<>(16);
    errorResultMap.put("code", customException.getCode());
    errorResultMap.put("message", customException.getMessage());
    return errorResultMap;
    }
    }

  • 相关阅读:
    C++学习网址
    python学习网址
    python之raw_input()函数
    APP营销模式
    计划任务
    多线程
    Spring Aware
    事件(Application Event)
    Spring 的AOP
    Java配置
  • 原文地址:https://www.cnblogs.com/xuxiaobai13/p/12067452.html
Copyright © 2011-2022 走看看