想根据枚举类中的code获取desc突然忘了怎么写了,还是记录一下吧
public enum ProjectTypeEnum {
NORMAL(1, "日常"),
SSSS(2, "SSSS");
private Integer code;
private String desc;
ProjectTypeEnum(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
public static ProjectTypeEnum select(Integer code) {
ProjectTypeEnum[] arr = ProjectTypeEnum.values(); 主要是这个忘记了,好尴尬
for(int i = 0; i < arr.length; i++) {
ProjectTypeEnum sumProjectTypeEnum = arr[i];
if(sumProjectTypeEnum.getCode() == code) {
return sumProjectTypeEnum;
}
}
return null;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}