From 46376023c5b0aa01489f8eba2aa832e978e8859e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Thu, 13 Apr 2023 17:22:56 +0800 Subject: [PATCH] =?UTF-8?q?feature=EF=BC=9A=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=99=A8=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=20entity?= =?UTF-8?q?=20=E5=89=8D=E5=90=8E=E7=BC=80=E9=85=8D=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/codegen.md | 8 ++++++- .../com/mybatisflex/codegen/Generator.java | 3 ++- .../codegen/config/GlobalConfig.java | 22 +++++++++++++++++++ .../main/resources/templates/enjoy/entity.tpl | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/docs/zh/codegen.md b/docs/zh/codegen.md index 9aaa16cc..b65a69df 100644 --- a/docs/zh/codegen.md +++ b/docs/zh/codegen.md @@ -91,13 +91,19 @@ GlobalConfig 支持更多的配置如下: ```java public class GlobalConfig { - + //代码生成目录 private String sourceDir; //entity 的包名 private String entityPackage; + //mapper 类的前缀 + private String entityClassPrefix = ""; + + //mapper 类的后缀 + private String entityClassSuffix = ""; + //entity 是否使用 Lombok private boolean entityWithLombok = false; diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java index 6d29180f..b0b35bca 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/Generator.java @@ -63,7 +63,8 @@ public class Generator { for (Table table : tables) { String entityPackagePath = globalConfig.getEntityPackage().replace(".", "/"); - File entityJavaFile = new File(globalConfig.getSourceDir(), entityPackagePath + "/" + table.buildEntityClassName() + ".java"); + File entityJavaFile = new File(globalConfig.getSourceDir(), entityPackagePath + "/" + + globalConfig.getEntityClassPrefix() + table.buildEntityClassName() + globalConfig.getEntityClassSuffix() + ".java"); if (!entityJavaFile.getParentFile().exists()) { if (!entityJavaFile.getParentFile().mkdirs()) { throw new IllegalStateException("Can not mkdirs by dir: " + entityJavaFile.getParentFile()); diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java index 113c7d64..23b7c4be 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java @@ -32,6 +32,12 @@ public class GlobalConfig { //entity 的包名 private String entityPackage; + //mapper 类的前缀 + private String entityClassPrefix = ""; + + //mapper 类的后缀 + private String entityClassSuffix = ""; + //entity 是否使用 Lombok private boolean entityWithLombok = false; @@ -100,6 +106,22 @@ public class GlobalConfig { this.entityPackage = entityPackage.trim(); } + public String getEntityClassPrefix() { + return entityClassPrefix; + } + + public void setEntityClassPrefix(String entityClassPrefix) { + this.entityClassPrefix = entityClassPrefix; + } + + public String getEntityClassSuffix() { + return entityClassSuffix; + } + + public void setEntityClassSuffix(String entityClassSuffix) { + this.entityClassSuffix = entityClassSuffix; + } + public boolean isEntityWithLombok() { return entityWithLombok; } diff --git a/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.tpl b/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.tpl index fb1de060..ba06e149 100644 --- a/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.tpl +++ b/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.tpl @@ -6,7 +6,7 @@ import #(importClass); #(table.buildTableAnnotation()) -public class #(table.buildEntityClassName()) { +public class #(globalConfig.entityClassPrefix ??)#(table.buildEntityClassName())#(globalConfig.entityClassSuffix ??) { #for(column: table.columns) #(column.buildAnnotations()) private #(column.propertySimpleType) #(column.property);