在正常的开发过程中可能需要对某个变量进行定义,把该变量放在枚举中以便后期的开发和维护。
一般情况下枚举中只使用get(),不使用set(),避免枚举值发生变化。
package com.wondersgroup.hnmi.jmggyw.common.enums;
import java.util.HashMap;
import java.util.Map;
/**
* @author sunchao
* @description 市县乡村组的级别
* @date 2019/10/6 17:52
*/
public enum Aab021Enum {
center("10", "中央"),
province("20", "省"),
city("40", "市、地区"),
county("50", "县(区)"),
county_q("51", "区"),
county_x("52", "县"),
country("60", "街道、镇、乡"),
country_jd("61", "街道"),
country_z("62", "镇"),
country_x("63", "乡"),
village("70", "居民、村民委员会"),
village_jm("71", "居民委员会"),
village_cm("72", "村民委员会"),
army("80", "军队"),
other("90", "其他"),
;
private static final Map<String, Aab021Enum> strToEnum = new HashMap<>();
static {
for (Aab021Enum type : Aab021Enum.values()) {
strToEnum.put(type.getCode(), type);
}
}
private String code;
private String msg;
Aab021Enum(String code, String msg) {
this.code = code;
this.msg = msg;
}
public static Aab021Enum fromString(String code) {
return strToEnum.get(code);
}
public String getCode() {
return code;
}
public String getMsg() {
return msg;
}
}