public enum Ethicy { 1("1", "汉族"), 2("2", "回族"), 3("3", "维吾尔族"), 4("4", "苗族"), 5("5", "藏族") ; private final String code; private final String value; Ethicy(String code, String value) { this.code = code; this.value = value; } public String getCode() { return code; } public String getValue() { return value; } public static Ethicy findByCode(String code) { for (Ethicy constant : values()) { if (constant.key.equals(code)) { return constant; } } return null; // 或者抛出 IllegalArgumentException } public static Ethicy findByValue(String value) { for (Ethicy constant : values()) { if (constant.value.equals(value)) { return constant; } } return null; // 或者抛出 IllegalArgumentException } }