第十节 枚举enum工具类定义

亮子 2023-10-02 13:42:29 10380 0 0 0
package com.shenmazong.shenmablogserver.enums;

public enum ShareStatusEnum {
    PRIVATE(0, "私密"),
    SHARE(1, "分享"),
    ;

    // 成员
    private Integer code;
    private String name;

    // 构造方法
    private ShareStatusEnum(int code, String name) {
        this.name = name;
        this.code = code;
    }

    // 普通方法
    public static String getName(int code) {
        for (ShareStatusEnum c : ShareStatusEnum.values()) {
            if (c.getCode() == code) {
                return c.name;
            }
        }
        return null;
    }

    // get set 方法
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
}