代码如下:
package com.newsee.nsservice.enums;
public enum ServiceTypeEnum {
REPAIR(1,"维修分类"),
COMPLAINT(2,"投诉分类"),
ADVISORY(3,"咨询分类"),
PRAISE(4,"表扬分类"),
SERVICE(5,"服务分类");
private Integer code;
private String desc;
// 普通方法(可以根据code获取名字)
public static String getName(int code) {
for (ServiceTypeEnum c : ServiceTypeEnum.values()) {
if (c.getCode() == code) {
return c.desc;
}
}
return null;
}
ServiceTypeEnum(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
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;
}
}
本文介绍了一种在Java中使用枚举类型的具体案例,通过定义服务类型枚举,实现了不同类型的服务分类,并提供了根据代码获取描述的方法。这有助于理解和实践枚举类型的使用,特别是在涉及固定分类场景的应用开发中。
590

被折叠的 条评论
为什么被折叠?



