列挙タイプ前後端は交互に列挙値をとり,列挙はリストに値を置く.

1617 ワード

バックエンドでのクラスの記述の列挙
public enum TaskTriggerTypeEnum {
    CHILD((byte) 1, " "),
    YOUTH((byte) 2, " ");
    Byte type;
    String desc;
    TaskTriggerTypeEnum(Byte type, String desc) {
        this.type = type;
        this.desc = desc;
    }
    public Byte getType() {
        return type;
    }
    public void setType(Byte type) {
        this.type = type;
    }
    public String getDesc() {
        return desc;
    }
    public void setDesc(String desc) {
        this.desc = desc;
    }
    public static boolean contain(Byte type) {
        if (null == type) {
            return false;
        }
        for (TaskTriggerTypeEnum taskTriggerTypeEnum : values()) {
            if (type == taskTriggerTypeEnum.getType()) {
                return true;
            }
        }
        return false;
    }
    public static TaskTriggerTypeEnum getEnumByType(Byte triggerType) {
        if (triggerType != null) {
            for (TaskTriggerTypeEnum flowTriggerType : TaskTriggerTypeEnum.values()) {
                if (flowTriggerType.getType().equals(triggerType)) {
                    return flowTriggerType;
                }
            }
        }
        return null;
    }
}
すべての列挙タイプの値をバックエンドで取得
@GetMapping(value = "/getTypeEnum")
// list , 
public List getAllTypeEnum() {
    List allValue = new ArrayList<>();
    for(TaskTriggerTypeEnum s :TaskTriggerTypeEnum.values()){
        Map map = new HashMap<>();
        map.put(s.getType(),s.getDesc());
        allValue.add(map);
    }
    return allValue;
}