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

      

  • 相关阅读:
    remove white space from read
    optimize the access speed of django website
    dowload image from requests
    run jupyter from command
    crawl wechat page
    python version 2.7 required which was not found in the registry windows 7
    health
    alternate rows shading using conditional formatting
    word
    【JAVA基础】static 关键字
  • 原文地址:https://www.cnblogs.com/irobotzz/p/12982629.html
Copyright © 2020-2023  润新知