Mybaist plus 枚举类型转化

MP提供了两种方式处理枚举映射

1、继承 implements IBaseEnum<T>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.common.auth.constants;
 
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
 
/**
 * 用户启用状态
 *
 * @author Yungui.zheng
 * @date 2020/05/11
 */
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum StateEnum implements IBaseEnum<Integer>{
 
    /**
     * 用户启用状态常量
     */
    DISABLED(0, "停用"),
    ENABLED(1, "启用"),
    UNKNOWN(-1,"未知");
 
    private final Integer value;
    private final String desc;
 
    StateEnum(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }
 
}

  

2、注解@EnumValue

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.common.auth.constants;
 
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
 
/**
 * 用户启用状态
 *
 * @author Yungui.zheng
 * @date 2020/05/11
 */
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum StateEnum implements IBaseEnum<Integer>{
 
    /**
     * 用户启用状态常量
     */
    DISABLED(0, "停用"),
    ENABLED(1, "启用"),
    UNKNOWN(-1,"未知");
 
    @EnumValue
    private final Integer value;
    private final String desc;
 
    StateEnum(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }
 
}

  

posted on   滚动的蛋  阅读(1728)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示