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