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