demo_back/output/NationEnum.java
2024-12-01 19:18:17 +08:00

42 lines
694 B
Java

public enum Nation {
A("A", "阿根廷"),
B("B", "巴西"),
C("C", "加拿大"),
D("D", "丹麦")
;
private final String code;
private final String value;
Nation(String code, String value) {
this.code = code;
this.value = value;
}
public String getCode() {
return code;
}
public String getValue() {
return value;
}
public static Nation findByCode(String code) {
for (Nation constant : values()) {
if (constant.key.equals(code)) {
return constant;
}
}
return null; // 或者抛出 IllegalArgumentException
}
public static Nation findByValue(String value) {
for (Nation constant : values()) {
if (constant.value.equals(value)) {
return constant;
}
}
return null; // 或者抛出 IllegalArgumentException
}
}