一:定义异常类:
public class BusinessException extends RuntimeException {
private Integer code;
public BusinessException() {
super();
}
public BusinessException(Integer code, String message) {
super(message);
this.code = code;
}
public BusinessException(String message) {
super(message);
}
public BusinessException(String message, Throwable cause) {
super(message, cause);
}
public BusinessException(Throwable cause) {
super(cause);
}
public BusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
}
二:Servic 层或者dao层抛出异常:
三:捕获异常:
(1)全局捕获异常
(2)controlle进行捕获异常