mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
feature:代码生成器添加配置 Mapper 前后缀配置的功能 close #I6TITQ
This commit is contained in:
parent
8cbec82681
commit
58dd10a9ce
@ -99,15 +99,24 @@ public class GlobalConfig {
|
|||||||
private String entityPackage;
|
private String entityPackage;
|
||||||
|
|
||||||
//entity 是否使用 Lombok
|
//entity 是否使用 Lombok
|
||||||
private Boolean entityWithLombok = false;
|
private boolean entityWithLombok = false;
|
||||||
|
|
||||||
//是否生成 mapper 类
|
//是否生成 mapper 类
|
||||||
private boolean mapperGenerateEnable = false;
|
private boolean mapperGenerateEnable = false;
|
||||||
|
|
||||||
|
//是否覆盖已经存在的 mapper
|
||||||
|
private boolean mapperOverwriteEnable = false;
|
||||||
|
|
||||||
|
//mapper 类的前缀
|
||||||
|
private String mapperClassPrefix;
|
||||||
|
|
||||||
|
//mapper 类的后缀
|
||||||
|
private String mapperClassSuffix = "Mapper";
|
||||||
|
|
||||||
//mapper 的包名
|
//mapper 的包名
|
||||||
private String mapperPackage;
|
private String mapperPackage;
|
||||||
|
|
||||||
//数据库表前缀
|
//数据库表前缀,多个前缀用英文逗号(,) 隔开
|
||||||
private String tablePrefix;
|
private String tablePrefix;
|
||||||
|
|
||||||
//逻辑删除的默认字段名称
|
//逻辑删除的默认字段名称
|
||||||
|
|||||||
@ -75,13 +75,21 @@ public class Generator {
|
|||||||
|
|
||||||
if (globalConfig.isMapperGenerateEnable()) {
|
if (globalConfig.isMapperGenerateEnable()) {
|
||||||
String mapperPackagePath = globalConfig.getMapperPackage().replace(".", "/");
|
String mapperPackagePath = globalConfig.getMapperPackage().replace(".", "/");
|
||||||
File mapperJavaFile = new File(globalConfig.getSourceDir(), mapperPackagePath + "/" + table.buildEntityClassName() + "Mapper.java");
|
|
||||||
|
|
||||||
|
File mapperJavaFile = new File(globalConfig.getSourceDir(), mapperPackagePath + "/" + globalConfig.getMapperClassPrefix()
|
||||||
|
+ table.buildEntityClassName() + globalConfig.getMapperClassSuffix() + ".java");
|
||||||
if (!mapperJavaFile.getParentFile().exists()) {
|
if (!mapperJavaFile.getParentFile().exists()) {
|
||||||
if (!mapperJavaFile.getParentFile().mkdirs()) {
|
if (!mapperJavaFile.getParentFile().mkdirs()) {
|
||||||
throw new IllegalStateException("Can not mkdirs by dir: " + mapperJavaFile.getParentFile());
|
throw new IllegalStateException("Can not mkdirs by dir: " + mapperJavaFile.getParentFile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templateEngine.generateMapper(globalConfig, table, mapperJavaFile);
|
|
||||||
|
if (mapperJavaFile.exists() && !globalConfig.isMapperOverwriteEnable()) {
|
||||||
|
//ignore
|
||||||
|
} else {
|
||||||
|
templateEngine.generateMapper(globalConfig, table, mapperJavaFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,6 +38,15 @@ public class GlobalConfig {
|
|||||||
//是否生成 mapper 类
|
//是否生成 mapper 类
|
||||||
private boolean mapperGenerateEnable = false;
|
private boolean mapperGenerateEnable = false;
|
||||||
|
|
||||||
|
//是否覆盖已经存在的 mapper
|
||||||
|
private boolean mapperOverwriteEnable = false;
|
||||||
|
|
||||||
|
//mapper 类的前缀
|
||||||
|
private String mapperClassPrefix;
|
||||||
|
|
||||||
|
//mapper 类的后缀
|
||||||
|
private String mapperClassSuffix = "Mapper";
|
||||||
|
|
||||||
//mapper 的包名
|
//mapper 的包名
|
||||||
private String mapperPackage;
|
private String mapperPackage;
|
||||||
|
|
||||||
@ -107,6 +116,33 @@ public class GlobalConfig {
|
|||||||
this.mapperGenerateEnable = mapperGenerateEnable;
|
this.mapperGenerateEnable = mapperGenerateEnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMapperOverwriteEnable() {
|
||||||
|
return mapperOverwriteEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMapperOverwriteEnable(boolean mapperOverwriteEnable) {
|
||||||
|
this.mapperOverwriteEnable = mapperOverwriteEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMapperClassPrefix() {
|
||||||
|
if (StringUtil.isBlank(mapperClassPrefix)){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return mapperClassPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMapperClassPrefix(String mapperClassPrefix) {
|
||||||
|
this.mapperClassPrefix = mapperClassPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMapperClassSuffix() {
|
||||||
|
return mapperClassSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMapperClassSuffix(String mapperClassSuffix) {
|
||||||
|
this.mapperClassSuffix = mapperClassSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMapperPackage() {
|
public String getMapperPackage() {
|
||||||
if (StringUtil.isBlank(mapperPackage)) {
|
if (StringUtil.isBlank(mapperPackage)) {
|
||||||
throw new IllegalStateException("mapperPackage can not be null or blank in GlobalConfig.");
|
throw new IllegalStateException("mapperPackage can not be null or blank in GlobalConfig.");
|
||||||
|
|||||||
@ -3,6 +3,6 @@ package #(globalConfig.mapperPackage);
|
|||||||
import com.mybatisflex.core.BaseMapper;
|
import com.mybatisflex.core.BaseMapper;
|
||||||
import #(globalConfig.entityPackage).#(table.buildEntityClassName());
|
import #(globalConfig.entityPackage).#(table.buildEntityClassName());
|
||||||
|
|
||||||
public interface #(table.buildEntityClassName())Mapper extends BaseMapper<#(table.buildEntityClassName())> {
|
public interface #(globalConfig.mapperClassPrefix ??)#(table.buildEntityClassName())#(globalConfig.mapperClassSuffix ??) extends BaseMapper<#(table.buildEntityClassName())> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user