mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
feat: add sourceDir config for generators
This commit is contained in:
parent
25682c1b1b
commit
e2723e0ef6
Binary file not shown.
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 197 KiB |
@ -27,6 +27,10 @@ import java.io.Serializable;
|
||||
public class ControllerConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8391630904705910611L;
|
||||
/**
|
||||
* 代码生成目录,当未配置时,使用 PackageConfig 的配置
|
||||
*/
|
||||
private String sourceDir;
|
||||
/**
|
||||
* Controller 类的前缀。
|
||||
*/
|
||||
@ -60,6 +64,14 @@ public class ControllerConfig implements Serializable {
|
||||
return superClass.getSimpleName();
|
||||
}
|
||||
|
||||
public String getSourceDir() {
|
||||
return sourceDir;
|
||||
}
|
||||
|
||||
public void setSourceDir(String sourceDir) {
|
||||
this.sourceDir = sourceDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类前缀。
|
||||
*/
|
||||
|
||||
@ -27,6 +27,11 @@ import java.io.Serializable;
|
||||
public class EntityConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6790274333595436008L;
|
||||
/**
|
||||
* 代码生成目录,当未配置时,使用 PackageConfig 的配置
|
||||
*/
|
||||
private String sourceDir;
|
||||
|
||||
/**
|
||||
* Entity 类的前缀。
|
||||
*/
|
||||
@ -82,6 +87,14 @@ public class EntityConfig implements Serializable {
|
||||
*/
|
||||
private int jdkVersion;
|
||||
|
||||
public String getSourceDir() {
|
||||
return sourceDir;
|
||||
}
|
||||
|
||||
public void setSourceDir(String sourceDir) {
|
||||
this.sourceDir = sourceDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类前缀。
|
||||
*/
|
||||
|
||||
@ -29,6 +29,11 @@ import java.io.Serializable;
|
||||
public class MapperConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1937442008907641534L;
|
||||
/**
|
||||
* 代码生成目录,当未配置时,使用 PackageConfig 的配置
|
||||
*/
|
||||
private String sourceDir;
|
||||
|
||||
/**
|
||||
* Mapper 类的前缀。
|
||||
*/
|
||||
@ -62,6 +67,14 @@ public class MapperConfig implements Serializable {
|
||||
return superClass.getSimpleName();
|
||||
}
|
||||
|
||||
public String getSourceDir() {
|
||||
return sourceDir;
|
||||
}
|
||||
|
||||
public void setSourceDir(String sourceDir) {
|
||||
this.sourceDir = sourceDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类前缀。
|
||||
*/
|
||||
|
||||
@ -44,7 +44,6 @@ public class PackageConfig implements Serializable {
|
||||
* Entity 所在包。
|
||||
*/
|
||||
private String entityPackage;
|
||||
|
||||
/**
|
||||
* Mapper 所在包。
|
||||
*/
|
||||
|
||||
@ -30,6 +30,11 @@ import java.io.Serializable;
|
||||
public class ServiceConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2152473328300910220L;
|
||||
/**
|
||||
* 代码生成目录,当未配置时,使用 PackageConfig 的配置
|
||||
*/
|
||||
private String sourceDir;
|
||||
|
||||
/**
|
||||
* Service 类的前缀。
|
||||
*/
|
||||
@ -58,6 +63,14 @@ public class ServiceConfig implements Serializable {
|
||||
return superClass.getSimpleName();
|
||||
}
|
||||
|
||||
public String getSourceDir() {
|
||||
return sourceDir;
|
||||
}
|
||||
|
||||
public void setSourceDir(String sourceDir) {
|
||||
this.sourceDir = sourceDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类前缀。
|
||||
*/
|
||||
|
||||
@ -27,6 +27,12 @@ import java.io.Serializable;
|
||||
public class ServiceImplConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 17115432462168151L;
|
||||
|
||||
/**
|
||||
* 代码生成目录,当未配置时,使用 PackageConfig 的配置
|
||||
*/
|
||||
private String sourceDir;
|
||||
|
||||
/**
|
||||
* ServiceImpl 类的前缀。
|
||||
*/
|
||||
@ -52,6 +58,14 @@ public class ServiceImplConfig implements Serializable {
|
||||
*/
|
||||
private boolean cacheExample;
|
||||
|
||||
public String getSourceDir() {
|
||||
return sourceDir;
|
||||
}
|
||||
|
||||
public void setSourceDir(String sourceDir) {
|
||||
this.sourceDir = sourceDir;
|
||||
}
|
||||
|
||||
public String buildSuperClassImport() {
|
||||
if (superClass == null) {
|
||||
return "com.mybatisflex.spring.service.impl.ServiceImpl";
|
||||
|
||||
@ -29,6 +29,10 @@ import java.io.Serializable;
|
||||
public class TableDefConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8137903163796008036L;
|
||||
/**
|
||||
* 代码生成目录,当未配置时,使用 PackageConfig 的配置
|
||||
*/
|
||||
private String sourceDir;
|
||||
/**
|
||||
* TableDef 类的前缀。
|
||||
*/
|
||||
@ -68,6 +72,14 @@ public class TableDefConfig implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public String getSourceDir() {
|
||||
return sourceDir;
|
||||
}
|
||||
|
||||
public void setSourceDir(String sourceDir) {
|
||||
this.sourceDir = sourceDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类前缀。
|
||||
*/
|
||||
|
||||
@ -21,6 +21,7 @@ import com.mybatisflex.codegen.config.PackageConfig;
|
||||
import com.mybatisflex.codegen.constant.TemplateConst;
|
||||
import com.mybatisflex.codegen.entity.Table;
|
||||
import com.mybatisflex.codegen.generator.IGenerator;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@ -54,8 +55,10 @@ public class ControllerGenerator implements IGenerator {
|
||||
PackageConfig packageConfig = globalConfig.getPackageConfig();
|
||||
ControllerConfig controllerConfig = globalConfig.getControllerConfig();
|
||||
|
||||
String sourceDir = StringUtil.isNotBlank(controllerConfig.getSourceDir()) ? controllerConfig.getSourceDir() : packageConfig.getSourceDir();
|
||||
|
||||
String controllerPackagePath = packageConfig.getControllerPackage().replace(".", "/");
|
||||
File controllerJavaFile = new File(packageConfig.getSourceDir(), controllerPackagePath + "/" +
|
||||
File controllerJavaFile = new File(sourceDir, controllerPackagePath + "/" +
|
||||
table.buildControllerClassName() + ".java");
|
||||
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ import com.mybatisflex.codegen.config.PackageConfig;
|
||||
import com.mybatisflex.codegen.constant.TemplateConst;
|
||||
import com.mybatisflex.codegen.entity.Table;
|
||||
import com.mybatisflex.codegen.generator.IGenerator;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@ -54,8 +55,10 @@ public class EntityGenerator implements IGenerator {
|
||||
PackageConfig packageConfig = globalConfig.getPackageConfig();
|
||||
EntityConfig entityConfig = globalConfig.getEntityConfig();
|
||||
|
||||
String sourceDir = StringUtil.isNotBlank(entityConfig.getSourceDir()) ? entityConfig.getSourceDir() : packageConfig.getSourceDir();
|
||||
|
||||
String entityPackagePath = packageConfig.getEntityPackage().replace(".", "/");
|
||||
File entityJavaFile = new File(packageConfig.getSourceDir(), entityPackagePath + "/" +
|
||||
File entityJavaFile = new File(sourceDir, entityPackagePath + "/" +
|
||||
table.buildEntityClassName() + ".java");
|
||||
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ import com.mybatisflex.codegen.config.PackageConfig;
|
||||
import com.mybatisflex.codegen.constant.TemplateConst;
|
||||
import com.mybatisflex.codegen.entity.Table;
|
||||
import com.mybatisflex.codegen.generator.IGenerator;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@ -54,8 +55,10 @@ public class MapperGenerator implements IGenerator {
|
||||
PackageConfig packageConfig = globalConfig.getPackageConfig();
|
||||
MapperConfig mapperConfig = globalConfig.getMapperConfig();
|
||||
|
||||
String sourceDir = StringUtil.isNotBlank(mapperConfig.getSourceDir()) ? mapperConfig.getSourceDir() : packageConfig.getSourceDir();
|
||||
|
||||
String mapperPackagePath = packageConfig.getMapperPackage().replace(".", "/");
|
||||
File mapperJavaFile = new File(packageConfig.getSourceDir(), mapperPackagePath + "/" +
|
||||
File mapperJavaFile = new File(sourceDir, mapperPackagePath + "/" +
|
||||
table.buildMapperClassName() + ".java");
|
||||
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ import com.mybatisflex.codegen.config.ServiceConfig;
|
||||
import com.mybatisflex.codegen.constant.TemplateConst;
|
||||
import com.mybatisflex.codegen.entity.Table;
|
||||
import com.mybatisflex.codegen.generator.IGenerator;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@ -54,8 +55,10 @@ public class ServiceGenerator implements IGenerator {
|
||||
PackageConfig packageConfig = globalConfig.getPackageConfig();
|
||||
ServiceConfig serviceConfig = globalConfig.getServiceConfig();
|
||||
|
||||
String sourceDir = StringUtil.isNotBlank(serviceConfig.getSourceDir()) ? serviceConfig.getSourceDir() : packageConfig.getSourceDir();
|
||||
|
||||
String servicePackagePath = packageConfig.getServicePackage().replace(".", "/");
|
||||
File serviceJavaFile = new File(packageConfig.getSourceDir(), servicePackagePath + "/" +
|
||||
File serviceJavaFile = new File(sourceDir, servicePackagePath + "/" +
|
||||
table.buildServiceClassName() + ".java");
|
||||
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ import com.mybatisflex.codegen.config.ServiceImplConfig;
|
||||
import com.mybatisflex.codegen.constant.TemplateConst;
|
||||
import com.mybatisflex.codegen.entity.Table;
|
||||
import com.mybatisflex.codegen.generator.IGenerator;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@ -54,8 +55,10 @@ public class ServiceImplGenerator implements IGenerator {
|
||||
PackageConfig packageConfig = globalConfig.getPackageConfig();
|
||||
ServiceImplConfig serviceImplConfig = globalConfig.getServiceImplConfig();
|
||||
|
||||
String sourceDir = StringUtil.isNotBlank(serviceImplConfig.getSourceDir()) ? serviceImplConfig.getSourceDir() : packageConfig.getSourceDir();
|
||||
|
||||
String serviceImplPackagePath = packageConfig.getServiceImplPackage().replace(".", "/");
|
||||
File serviceImplJavaFile = new File(packageConfig.getSourceDir(), serviceImplPackagePath + "/" +
|
||||
File serviceImplJavaFile = new File(sourceDir, serviceImplPackagePath + "/" +
|
||||
table.buildServiceImplClassName() + ".java");
|
||||
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ import com.mybatisflex.codegen.config.TableDefConfig;
|
||||
import com.mybatisflex.codegen.constant.TemplateConst;
|
||||
import com.mybatisflex.codegen.entity.Table;
|
||||
import com.mybatisflex.codegen.generator.IGenerator;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@ -54,8 +55,10 @@ public class TableDefGenerator implements IGenerator {
|
||||
PackageConfig packageConfig = globalConfig.getPackageConfig();
|
||||
TableDefConfig tableDefConfig = globalConfig.getTableDefConfig();
|
||||
|
||||
String sourceDir = StringUtil.isNotBlank(tableDefConfig.getSourceDir()) ? tableDefConfig.getSourceDir() : packageConfig.getSourceDir();
|
||||
|
||||
String tableDefPackagePath = packageConfig.getTableDefPackage().replace(".", "/");
|
||||
File tableDefJavaFile = new File(packageConfig.getSourceDir(), tableDefPackagePath + "/" +
|
||||
File tableDefJavaFile = new File(sourceDir, tableDefPackagePath + "/" +
|
||||
table.buildTableDefClassName() + ".java");
|
||||
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ spring:
|
||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/flex_test
|
||||
username: root
|
||||
password: 12345678
|
||||
password: 123456
|
||||
# driver-class-name:
|
||||
# datasource:
|
||||
# driver-class-name: org.h2.Driver
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user