mynameislichengeng/java-create-cls-enum icon
public
Published on 4/7/2025
java-创建类-枚举

创建枚举类

Prompts
java-create-cls-enum
创建枚举类
如果有这样的值:
固定值:
1-首次30日活跃时间为空
2-首次有效使用时间为空
3-首次有效时间为空
4-驾校服务工单为空
5-数据迁移工单为空

那么创建枚举类,是这样的。

package cn.mucang.lexus.task.common.enums;

import cn.mucang.simple.mvc.exception.ClientException;

/**
 * @author by licheng01
 * @date 2025/4/7 15:11
 * @description
 */
public enum ReportEmptyEnum {
    FIRST_30_DAYS_ACTIVE_NULL(1, "首次30日活跃时间为空"),
    FIRST_VALID_USE_NULL(2, "首次有效使用时间为空"),
    FIRST_VALID_TIME_NULL(3, "首次有效时间为空"),
    DRIVING_SCHOOL_ORDER_NULL(4, "驾校服务工单为空"),
    DATA_MIGRATION_ORDER_NULL(5, "数据迁移工单为空");

    private final int code;
    private final String desc;

    ReportEmptyEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static ReportEmptyEnum fromCode(Integer code) {
        if (code == null) {
            throw new ClientException("状态码code不能为空");
        }
        for (ReportEmptyEnum status : ReportEmptyEnum.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new ClientException("状态码code非法");
    }
}

希望之后,我给出对应的key-value后,也按上面的格式创建。

创建的时候,如果告诉了枚举类,就用告诉的,如果没有告诉,先询问一下