Giter VIP home page Giter VIP logo

linkey-mybatis-plus-generator's Introduction

linkey-mybatis-plus-generator

基于官方mybatis-plus-generator3.3.0 增强-生成枚举类

增强说明

根据表字段tinyint数据类型以及特定注释格式生成枚举类 注释格式必须要符合 设备故障状态:{0:异常 , 1:正常} 这种格式下才能正常解析生成
注:注释中的冒号与逗号均为中文符号 现仅支持mysql与vm模板,其他可根据源码自行扩展

例子

类型 注释
id bigint 主键
sex tinyint 年龄:{0:男 , 1:女}
is_good tinyint 是否优秀学生:{0:否 , 1:是}
birth datetime 生日

程序会自动筛选sex和is_good为枚举类

生成enum格式类如下 public class TableEnum {

 // 性别枚举
  public enum SexEnum {
    SEX_0(0, "男"),
    SEX_1(1, "女"),
          ;

    private Integer key;
    private String value;

    SexEnum(Integer key, String value) {
        this.key = key;
        this.value = value;
    }

    public Integer getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    static public SexEnum get(Integer key) {
        for (SexEnum e : SexEnum.values()) {
            if (e.getKey().equals(key)) {
                return e;
            }
        }
        return SEX_0;
    }
}

// 是否优秀学生枚举
public enum IsGoodEnum {
    IS_GOOD_0(0, "否"),
    IS_GOOD_1(1, "是"),
          ;

    private Integer key;
    private String value;

    IsGoodEnum(Integer key, String value) {
        this.key = key;
        this.value = value;
    }

    public Integer getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    static public IsGoodEnum get(Integer key) {
        for (IsGoodEnum e : IsGoodEnum.values()) {
            if (e.getKey().equals(key)) {
                return e;
            }
        }
        return IS_GOOD_0;
    }
}

}

启动类配置

     String templatePathEnumJava = "/templates/enum.java.vm";
    // 自定义配置会被优先输出
    focList.add(new FileOutConfig(templatePathEnumJava) {
        @Override
        public String outputFile(TableInfo tableInfo) {
            return projectPath
                    + "/src/main/java" + RELATIVE_PATH + "/"  + moduleName  + "/enums/"
                    + tableInfo.getEnumName() + StringPool.DOT_JAVA;
        }
    });

    cfg.setFileOutConfigList(focList);
    
    
    ........
    
    
    templateConfig.setEnumName(null);  

本项目启动类为 MybatisGenerator.java

后续优化

1.生成枚举类中的默认枚举应该取表中字段的默认值

反馈与建议

linkey-mybatis-plus-generator's People

Contributors

zhujinghuic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.