Mybatis-plus3.5版本查询支持枚举返回

文章介绍了如何在Mybatis-Plus3.5版本中定义枚举类,包括使用@JsonFormat注解处理前端显示,实现IEnum接口以处理数据库字段,以及在实体类中使用枚举类型的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.定义枚举类(mybatis-plus 3.5版本适用):

1 (重要) @JsonFormat 表示返回前端是此字段(重要)或者 标注在类上@JsonFormat(shape = JsonFormat.Shape.OBJECT)前端就会显示枚举的key和value

2 implements IEnum 重写getValue()方法返回数据库存的字段

@Getter
public enum BuryingPointTypeEnum implements IEnum<String> {

    MORE_THAN_ONE_QUEEN("MORE_THAN_ONE_QUEEN", "型号匹配到多个队列"),

    RE_ACCESS("RE_ACCESS", "工程师重新接入"),
    MODEL_STOP_SERVICE("MODEL_STOP_SERVICE", "型号停服"),

    ENGINEEER_ONLINE("ENGINEEER_ONLINE", "工程师上线"),

    ENGINEEER_OFFLINE("ENGINEEER_OFFLINE", "工程师离线"),
    ;


    private String type;
    @JsonFormat
    private String name;

    BuryingPointTypeEnum(String type, String name) {
        this.type = type;
        this.name = name;
    }

    public static BuryingPointTypeEnum getByDefault(String type, BuryingPointTypeEnum defaultValue) {
        return Arrays.stream(values()).filter(e -> e.getType().equals(type)).findFirst().orElse(defaultValue);
    }

    public static BuryingPointTypeEnum getByType(String type) {
        return getByDefault(type, null);
    }

    @Override
    public String getValue() {
        return this.type;
    }
}

二 使用

在bean中类上使用枚举,就ok啦

 @ApiModelProperty(value = "埋点类型")
    @TableField(value = "type")
    private BuryingPointTypeEnum type;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值