如何定义枚举类型,包含两个字段。
public enum TypeNnum {
TYPE_1("TYPE_1", 1),
TYPE_2("TYPE_2", 2),
;
private String name;
private Integer value;
TypeNnum( String name, Integer value) {
this.value = value;
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getValue() {
return value;
}
public void setValue(Integer value) {
this.value = value;
}
public static TypeNnum getByName(String type) {
for (TypeNnum value : TypeNnum.values()) {
if (StringUtils.equals(value.getName(), type)) {
return value;
}
}
return null;
}
}