Solo  当前访客:1 开始使用

枚举类初始化


1、idea下载插件: EnumGenerator

2、在枚举类中点击generator菜单(alt+insert),选中EnumGenerator
image.png

public enum RoleEnum {

    fd("FD", "法人代表"),
    gd("GD", "股东");

    private String typeId;
    private String typeName;

    RoleEnum(String typeId, String typeName) {
        this.typeId = typeId;
        this.typeName = typeName;
    }

    public String getTypeId() {
        return typeId;
    }

    public String getTypeName() {
        return typeName;
    }
    public static String getTypeNameById(String typeId) {
        String value ="";
        RoleEnum[] values = values();

        for(int i = 0; i < values.length; ++i) {
            RoleEnum type = values[i];
            if(type.getTypeId().equals(typeId)) {
                value = type.getTypeName();
                break;
            }
        }
        return value;
    }
}
//获取值:
RoleEnum.getTypeNameById(role)
0 0