generator-enhance

基于个人需求对Mybatis-plus进行扩展开发

License

License

GroupId

GroupId

io.github.wilson-he
ArtifactId

ArtifactId

generator-enhance
Last Version

Last Version

0.3.6
Release Date

Release Date

Type

Type

jar
Description

Description

generator-enhance
基于个人需求对Mybatis-plus进行扩展开发
Project URL

Project URL

https://github.com/Wilson-He/generator-enhance
Source Code Management

Source Code Management

https://github.com/Wilson-He/generator-enhance

Download generator-enhance

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.wilson-he/generator-enhance/ -->
<dependency>
    <groupId>io.github.wilson-he</groupId>
    <artifactId>generator-enhance</artifactId>
    <version>0.3.6</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.wilson-he/generator-enhance/
implementation 'io.github.wilson-he:generator-enhance:0.3.6'
// https://jarcasting.com/artifacts/io.github.wilson-he/generator-enhance/
implementation ("io.github.wilson-he:generator-enhance:0.3.6")
'io.github.wilson-he:generator-enhance:jar:0.3.6'
<dependency org="io.github.wilson-he" name="generator-enhance" rev="0.3.6">
  <artifact name="generator-enhance" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.wilson-he', module='generator-enhance', version='0.3.6')
)
libraryDependencies += "io.github.wilson-he" % "generator-enhance" % "0.3.6"
[io.github.wilson-he/generator-enhance "0.3.6"]

Dependencies

compile (6)

Group / Artifact Type Version
com.baomidou : mybatis-plus-extension jar 3.1.1
org.apache.velocity : velocity-engine-core jar 2.0
org.freemarker : freemarker jar 2.3.28
com.ibeetl : beetl jar 2.9.8
org.apache.commons : commons-lang3 jar 3.8
com.google.guava : guava jar 27.1-jre

provided (3)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.16.22
mysql : mysql-connector-java jar 5.1.46
org.springframework.boot : spring-boot-starter-web jar 2.0.3.RELEASE

Project Modules

There are no modules declared in this project.

基于Mybatis-plus生成器基础上进行扩展,主要扩展功能如下:

  • 添加根据数据库注释生成常量类
  • 添加spring数据库配置(spring.datasource.url,username,password,driver-class-name)读取
  • 添加默认配置
  • 排除含指定关键字的表Service、Controller类的生成
  • 将默认生成目录更改为当前root模块的output目录下

依赖

<dependency>
    <groupId>io.github.wilson-he</groupId>
    <artifactId>generator-enhance</artifactId>
    <version>LATEST</version>
 </dependency>

快速开始

  • Simple Start

     public class CustomGeneratorApplication {
         public static void main(String[] args) throws IOException {
             // 支持yml、properties配置
             DefaultGeneratorConfigFactory.defaultAutoGenerator("application.yml", "io.github.test")
                     .execute();
             // DefaultGeneratorConfigFactory.defaultAutoGenerator("url","username","password", Driver.class,"io.github.wilson-he");
         }
     }
    
  • application.yml

     spring:
       datasource:
         username: root
         password: tiger
         driver-class-name: com.mysql.cj.jdbc.Driver
         url: jdbc:mysql://localhost:3306/wilson?useUnicode=true&characterEncoding=UTF-8
    
  • 扩展配置

    DefaultGeneratorConfigFactory.defaultAutoGenerator("application.yml", "io.github.test")
        .getStrategy()
        // 设置输出目录,不设置则默认生成到项目root模块的output目录下
        // .setOutputDir("E:\\project\\payment\\output")
        .setLogicDeleteFieldName("is_delete")
        // 不生成表名含detail、relation的Service、Controller
        .excludeKeywords("detail", "relation")
        // 只生成名表名pay、base的Service、Controller
        .includeKeywords("pay", "base")
        .backGenerator()
        // 设置生成哪些模板
        .getTemplate()
        // 不生成常量类
        .excludeConstant()
        // 不生成Controller模板类
        .excludeController()
        .backGenerator()
        .execute();
    }
    
  • SQL常量字段注释范式(user-test.sql含DDL范式demo)

    • comment({db_val}:{val_comment}-{map.key}), 例:删除标志量(1:已删除-YES, 0:未删除-NO)
    • comment({db_val}:{val_comment}), 例:删除标志量(YES:已删除, NO:未删除)
  • 常量模板类生成范例

    public interface UserBaseConstant {
    
       /**
        * 删除(0-未删除NO,1-已删除YES)
        */
       interface IsDelete {
           /**
            * 未删除
            */
           Integer NO = 0;
           /**
            * 已删除
            */
           Integer YES = 1;
           Map<Integer, String> MAP = ImmutableBiMap.of(
                   0, "未删除",
                   1, "已删除");
       }
    
       /**
        * 状态(ENABLE-启用,DISABLE-禁用)
        */
       interface Status {
           /**
            * 启用
            */
           String ENABLE = "ENABLE";
           /**
            * 禁用
            */
           String DISABLE = "DISABLE";
           Map<String, String> MAP = ImmutableBiMap.of(
                   "ENABLE", "启用",
                   "DISABLE", "禁用");
       }
    }
    

各版本更新内容

Versions

Version
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.0.1.RELEASE