码迷,mamicode.com
首页 > 其他好文 > 详细

枚举类

时间:2018-03-21 13:53:01      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:orm   void   post   ++   pre   blog   code   desc   style   

想根据枚举类中的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;
}

}


枚举类

标签:orm   void   post   ++   pre   blog   code   desc   style   

原文地址:https://www.cnblogs.com/zhangqian27/p/8616103.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!