Mybaist plus 枚举类型转化


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

1、继承 implements IBaseEnum<T>

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

  

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;
    }

}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM