定义一个枚举类:EnumTest,其中 变量包含 : code 和 value 两种属性。
public class EnumTest {
/**
* 这里是一个枚举类
*/
public enum TestEnum {
STATE_ONE("1", "状态一"),
STATE_TWO("2", "状态二"),
STATE_THREE("3", "状态三"),
STATE_FOUR("4", "状态四");
private String code;
private String value;
TestEnum(String code, String value) {
this.code = code;
this.value = value;
}
public String getCode() {
return code;
}
public String getValue() {
return value;
}
//根据code获取对应的value值
public static String getValueByCode(String code) {
if (StringUtils.isEmpty(code)) {
return null;
}
for (TestEnum testEnum : EnumTest.TestEnum.values()) {
if (testEnum.code.equals(code)) {
return