java的key-value的枚举转换

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);
    }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值