feature:代码生成器添加配置 entity 前后缀配置的功能

This commit is contained in:
开源海哥 2023-04-13 17:22:56 +08:00
parent 58dd10a9ce
commit 46376023c5
4 changed files with 32 additions and 3 deletions

View File

@ -98,6 +98,12 @@ public class GlobalConfig {
//entity 的包名 //entity 的包名
private String entityPackage; private String entityPackage;
//mapper 类的前缀
private String entityClassPrefix = "";
//mapper 类的后缀
private String entityClassSuffix = "";
//entity 是否使用 Lombok //entity 是否使用 Lombok
private boolean entityWithLombok = false; private boolean entityWithLombok = false;

View File

@ -63,7 +63,8 @@ public class Generator {
for (Table table : tables) { for (Table table : tables) {
String entityPackagePath = globalConfig.getEntityPackage().replace(".", "/"); 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().exists()) {
if (!entityJavaFile.getParentFile().mkdirs()) { if (!entityJavaFile.getParentFile().mkdirs()) {
throw new IllegalStateException("Can not mkdirs by dir: " + entityJavaFile.getParentFile()); throw new IllegalStateException("Can not mkdirs by dir: " + entityJavaFile.getParentFile());

View File

@ -32,6 +32,12 @@ public class GlobalConfig {
//entity 的包名 //entity 的包名
private String entityPackage; private String entityPackage;
//mapper 类的前缀
private String entityClassPrefix = "";
//mapper 类的后缀
private String entityClassSuffix = "";
//entity 是否使用 Lombok //entity 是否使用 Lombok
private boolean entityWithLombok = false; private boolean entityWithLombok = false;
@ -100,6 +106,22 @@ public class GlobalConfig {
this.entityPackage = entityPackage.trim(); 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() { public boolean isEntityWithLombok() {
return entityWithLombok; return entityWithLombok;
} }

View File

@ -6,7 +6,7 @@ import #(importClass);
#(table.buildTableAnnotation()) #(table.buildTableAnnotation())
public class #(table.buildEntityClassName()) { public class #(globalConfig.entityClassPrefix ??)#(table.buildEntityClassName())#(globalConfig.entityClassSuffix ??) {
#for(column: table.columns) #(column.buildAnnotations()) #for(column: table.columns) #(column.buildAnnotations())
private #(column.propertySimpleType) #(column.property); private #(column.propertySimpleType) #(column.property);