package com.ruoyi.onething.jaxbdc.entity; import lombok.Getter; import org.springframework.stereotype.Service; /** * @ClassName BdcToTaxEnum * @Description 不动产字典值映射税务字典值 * @Author liuz * @Date 2023/11/13 10:20 * @Version 1.0 */ @Getter @Service public enum BdcToTaxEnum { SFZ("1", "201"), ANOTHER_SYSTEM("10", "另一个系统"); private final String value; private final String description; BdcToTaxEnum(String value, String description) { this.value = value; this.description = description; } public String getValue() { return value; } public String getDescription() { return description; } public static String getDescriptionByValue(String value) { for (BdcToTaxEnum type : BdcToTaxEnum.values()) { if (value.equalsIgnoreCase(type.getValue())) { return type.getDescription(); } } throw new RuntimeException("不动产和税务字典值转换失败"); // return null; // 或者抛出异常 } public static BdcToTaxEnum getTypeByValue(String value) { for (BdcToTaxEnum type : BdcToTaxEnum.values()) { if (value.equalsIgnoreCase(type.getValue())) { return type; } } throw new RuntimeException("不动产和税务字典值转换失败"); } public static void main(String[] args) { String descriptionByValue = BdcToTaxEnum.getDescriptionByValue("1"); System.out.println(descriptionByValue); } }
java的key-value的枚举转换
最新推荐文章于 2024-08-05 02:10:40 发布