在日常开发中我们会用到枚举
@Slf4j
public enum ExceptionStateEnums {
NO_HANDLE(0,"未处置"),
HANDLED(1,"已处置");
Integer code;
String state;
ExceptionStateEnums(Integer code, String state) {
this.code = code;
this.state = state;
}
public Integer getCode() {
return code;
}
public String getState() {
return state;
}
public static String getByCode(Integer code) {
for (ExceptionStateEnums value : values()) {
if (code.equals(value.code)) {
return value.getState();
}
}
// log.error("不存在数据类型");
throw new RuntimeException ("不存在数据类型");
}
}