首页 > 其他 > 详细

枚举的使用

时间:2020-01-18 18:19:46      阅读:77      评论:0      收藏:0      [点我收藏+]

枚举类的定义

 1、可以用于定义常量

 2、根据类型code获取对应的中文意思

public enum VacationTypes {
    //请假类型 1、年休 2、病假 3、事假 4、工伤假 5、婚假 6、产假 7、护理假 8、丧假
    FuneralLeave("8","丧假"),
    NursingLeave("7","护理假"),
    MaternityLeave("6","产假"),
    MarriageLeave("5","婚假"),
    InjuryLeave("4","工伤假"),
    CompassionateLeave("3","事假"),
    SickLeave("2","病假"),
    AnnualLeave("1","年休");


    private String code;
    private String message;

    public static String getValue(String key) {
        VacationTypes[] values = values();
        for (VacationTypes type : values) {
            if (type.getCode().equals(key)) {
                return type.getMessage();
            }
        }
        return "";
    }

    VacationTypes( String code,String message) {
        this.code = code;
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}

根据code获取中文

VacationTypes.getValue(type);

获取对应的code

VacationTypes.FuneralLeave.getCode()

枚举的使用

原文:https://www.cnblogs.com/qq376324789/p/12209594.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!