⚡ 优化代码,符合阿里巴巴规范
This commit is contained in:
parent
d2d9cdccc2
commit
5da0335b61
|
|
@ -87,12 +87,8 @@ public class BladeGenerator {
|
||||||
private Boolean isSwagger2 = Boolean.TRUE;
|
private Boolean isSwagger2 = Boolean.TRUE;
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
// 获取配置文件
|
|
||||||
Properties props = getProperties();
|
Properties props = getProperties();
|
||||||
// 代码生成器
|
|
||||||
AutoGenerator mpg = new AutoGenerator();
|
AutoGenerator mpg = new AutoGenerator();
|
||||||
|
|
||||||
// 全局配置
|
|
||||||
GlobalConfig gc = new GlobalConfig();
|
GlobalConfig gc = new GlobalConfig();
|
||||||
String outputDir = getOutputDir();
|
String outputDir = getOutputDir();
|
||||||
String author = props.getProperty("author");
|
String author = props.getProperty("author");
|
||||||
|
|
@ -100,25 +96,10 @@ public class BladeGenerator {
|
||||||
gc.setAuthor(author);
|
gc.setAuthor(author);
|
||||||
gc.setFileOverride(true);
|
gc.setFileOverride(true);
|
||||||
gc.setOpen(false);
|
gc.setOpen(false);
|
||||||
/**
|
|
||||||
* 开启 activeRecord 模式
|
|
||||||
*/
|
|
||||||
gc.setActiveRecord(false);
|
gc.setActiveRecord(false);
|
||||||
/**
|
|
||||||
* XML 二级缓存
|
|
||||||
*/
|
|
||||||
gc.setEnableCache(false);
|
gc.setEnableCache(false);
|
||||||
/**
|
|
||||||
* XML ResultMap
|
|
||||||
*/
|
|
||||||
gc.setBaseResultMap(true);
|
gc.setBaseResultMap(true);
|
||||||
/**
|
|
||||||
* XML columList
|
|
||||||
*/
|
|
||||||
gc.setBaseColumnList(true);
|
gc.setBaseColumnList(true);
|
||||||
/**
|
|
||||||
* 自定义文件命名,注意 %s 会自动填充表实体属性!
|
|
||||||
*/
|
|
||||||
gc.setMapperName("%sMapper");
|
gc.setMapperName("%sMapper");
|
||||||
gc.setXmlName("%sMapper");
|
gc.setXmlName("%sMapper");
|
||||||
gc.setServiceName("I%sService");
|
gc.setServiceName("I%sService");
|
||||||
|
|
@ -126,8 +107,6 @@ public class BladeGenerator {
|
||||||
gc.setControllerName("%sController");
|
gc.setControllerName("%sController");
|
||||||
gc.setSwagger2(isSwagger2);
|
gc.setSwagger2(isSwagger2);
|
||||||
mpg.setGlobalConfig(gc);
|
mpg.setGlobalConfig(gc);
|
||||||
|
|
||||||
// 数据源配置
|
|
||||||
DataSourceConfig dsc = new DataSourceConfig();
|
DataSourceConfig dsc = new DataSourceConfig();
|
||||||
String driverName = props.getProperty("spring.datasource.driver-class-name");
|
String driverName = props.getProperty("spring.datasource.driver-class-name");
|
||||||
if (StringUtil.containsAny(driverName, DbType.MYSQL.getDb())) {
|
if (StringUtil.containsAny(driverName, DbType.MYSQL.getDb())) {
|
||||||
|
|
@ -138,45 +117,23 @@ public class BladeGenerator {
|
||||||
dsc.setTypeConvert(new PostgreSqlTypeConvert());
|
dsc.setTypeConvert(new PostgreSqlTypeConvert());
|
||||||
}
|
}
|
||||||
dsc.setUrl(props.getProperty("spring.datasource.url"));
|
dsc.setUrl(props.getProperty("spring.datasource.url"));
|
||||||
|
|
||||||
dsc.setDriverName(driverName);
|
dsc.setDriverName(driverName);
|
||||||
dsc.setUsername(props.getProperty("spring.datasource.username"));
|
dsc.setUsername(props.getProperty("spring.datasource.username"));
|
||||||
dsc.setPassword(props.getProperty("spring.datasource.password"));
|
dsc.setPassword(props.getProperty("spring.datasource.password"));
|
||||||
mpg.setDataSource(dsc);
|
mpg.setDataSource(dsc);
|
||||||
|
|
||||||
// 策略配置
|
// 策略配置
|
||||||
StrategyConfig strategy = new StrategyConfig();
|
StrategyConfig strategy = new StrategyConfig();
|
||||||
// strategy.setCapitalMode(true);// 全局大写命名
|
// strategy.setCapitalMode(true);// 全局大写命名
|
||||||
// strategy.setDbColumnUnderline(true);//全局下划线命名
|
// strategy.setDbColumnUnderline(true);//全局下划线命名
|
||||||
|
|
||||||
/**
|
|
||||||
* 表名生成策略
|
|
||||||
*/
|
|
||||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||||
/**
|
|
||||||
* 字段名生成策略
|
|
||||||
*/
|
|
||||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||||
/**
|
|
||||||
* 此处可以修改为您的表前缀
|
|
||||||
*/
|
|
||||||
strategy.setTablePrefix(tablePrefix);
|
strategy.setTablePrefix(tablePrefix);
|
||||||
|
|
||||||
if (includeTables.length > 0) {
|
if (includeTables.length > 0) {
|
||||||
/**
|
|
||||||
* 需要生成的表
|
|
||||||
*/
|
|
||||||
strategy.setInclude(includeTables);
|
strategy.setInclude(includeTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (excludeTables.length > 0) {
|
if (excludeTables.length > 0) {
|
||||||
/**
|
|
||||||
* 排除生成的表
|
|
||||||
*/
|
|
||||||
strategy.setExclude(excludeTables);
|
strategy.setExclude(excludeTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (hasSuperEntity) {
|
if (hasSuperEntity) {
|
||||||
strategy.setSuperEntityClass("org.springblade.core.mp.base.BaseEntity");
|
strategy.setSuperEntityClass("org.springblade.core.mp.base.BaseEntity");
|
||||||
strategy.setSuperEntityColumns(superEntityColumns);
|
strategy.setSuperEntityColumns(superEntityColumns);
|
||||||
|
|
@ -186,15 +143,12 @@ public class BladeGenerator {
|
||||||
strategy.setSuperServiceClass("com.baomidou.mybatisplus.extension.service.IService");
|
strategy.setSuperServiceClass("com.baomidou.mybatisplus.extension.service.IService");
|
||||||
strategy.setSuperServiceImplClass("com.baomidou.mybatisplus.extension.service.impl.ServiceImpl");
|
strategy.setSuperServiceImplClass("com.baomidou.mybatisplus.extension.service.impl.ServiceImpl");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 自定义 controller 父类
|
// 自定义 controller 父类
|
||||||
strategy.setSuperControllerClass("org.springblade.core.boot.ctrl.BladeController");
|
strategy.setSuperControllerClass("org.springblade.core.boot.ctrl.BladeController");
|
||||||
|
|
||||||
strategy.setEntityBuilderModel(false);
|
strategy.setEntityBuilderModel(false);
|
||||||
strategy.setEntityLombokModel(true);
|
strategy.setEntityLombokModel(true);
|
||||||
strategy.setControllerMappingHyphenStyle(true);
|
strategy.setControllerMappingHyphenStyle(true);
|
||||||
mpg.setStrategy(strategy);
|
mpg.setStrategy(strategy);
|
||||||
|
|
||||||
// 包配置
|
// 包配置
|
||||||
PackageConfig pc = new PackageConfig();
|
PackageConfig pc = new PackageConfig();
|
||||||
// 控制台扫描
|
// 控制台扫描
|
||||||
|
|
@ -204,9 +158,12 @@ public class BladeGenerator {
|
||||||
pc.setEntity("entity");
|
pc.setEntity("entity");
|
||||||
pc.setXml("mapper");
|
pc.setXml("mapper");
|
||||||
mpg.setPackageInfo(pc);
|
mpg.setPackageInfo(pc);
|
||||||
|
mpg.setCfg(getInjectionConfig());
|
||||||
|
mpg.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private InjectionConfig getInjectionConfig() {
|
||||||
String servicePackage = serviceName.split("-").length > 1 ? serviceName.split("-")[1] : serviceName;
|
String servicePackage = serviceName.split("-").length > 1 ? serviceName.split("-")[1] : serviceName;
|
||||||
|
|
||||||
// 自定义配置
|
// 自定义配置
|
||||||
InjectionConfig cfg = new InjectionConfig() {
|
InjectionConfig cfg = new InjectionConfig() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -279,9 +236,7 @@ public class BladeGenerator {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cfg.setFileOutConfigList(focList);
|
cfg.setFileOutConfigList(focList);
|
||||||
mpg.setCfg(cfg);
|
return cfg;
|
||||||
|
|
||||||
mpg.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user