Enum

 

public enum GenderEnum {
    MAN("1","男"),
    WOMAN("2","女");

    String code;
    String name;
    GenderEnum(String code,String name){
        this.code = code;
        this.name = name;
    }

    public static String getName(String code){
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (GenderEnum gender : GenderEnum.values()) {
            if (gender.getCode() == code) {
                return gender.getName();
            }
        }
        return null;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

 

posted on 2020-04-02 17:40  LJD泊水  阅读(157)  评论(0编辑  收藏  举报