mirror of
https://github.com/chillzhuang/blade-tool
synced 2024-12-12 12:19:27 +08:00
⬆️ 升级适配 mybatis-plus-generator 3.5.1
This commit is contained in:
parent
a8312fc058
commit
00fb785875
@ -36,7 +36,7 @@ public class CodeGenerator {
|
|||||||
/**
|
/**
|
||||||
* 代码生成的包名
|
* 代码生成的包名
|
||||||
*/
|
*/
|
||||||
public static String PACKAGE_NAME = "org.springblade.system";
|
public static String PACKAGE_NAME = "org.springblade.test";
|
||||||
/**
|
/**
|
||||||
* 前端代码生成所属系统
|
* 前端代码生成所属系统
|
||||||
*/
|
*/
|
||||||
@ -44,7 +44,7 @@ public class CodeGenerator {
|
|||||||
/**
|
/**
|
||||||
* 前端代码生成地址
|
* 前端代码生成地址
|
||||||
*/
|
*/
|
||||||
public static String PACKAGE_WEB_DIR = "/Users/chill/Workspaces/product/Saber";
|
public static String PACKAGE_WEB_DIR = "/Users/chill/Workspaces/test/Saber";
|
||||||
/**
|
/**
|
||||||
* 需要去掉的表前缀
|
* 需要去掉的表前缀
|
||||||
*/
|
*/
|
||||||
@ -65,7 +65,10 @@ public class CodeGenerator {
|
|||||||
* 基础业务字段
|
* 基础业务字段
|
||||||
*/
|
*/
|
||||||
public static String[] SUPER_ENTITY_COLUMNS = {"create_time", "create_user", "update_time", "update_user", "status", "is_deleted"};
|
public static String[] SUPER_ENTITY_COLUMNS = {"create_time", "create_user", "update_time", "update_user", "status", "is_deleted"};
|
||||||
|
/**
|
||||||
|
* 是否包含包装器
|
||||||
|
*/
|
||||||
|
public static Boolean HAS_WRAPPER = Boolean.TRUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RUN THIS
|
* RUN THIS
|
||||||
@ -82,6 +85,7 @@ public class CodeGenerator {
|
|||||||
generator.setExcludeTables(EXCLUDE_TABLES);
|
generator.setExcludeTables(EXCLUDE_TABLES);
|
||||||
generator.setHasSuperEntity(HAS_SUPER_ENTITY);
|
generator.setHasSuperEntity(HAS_SUPER_ENTITY);
|
||||||
generator.setSuperEntityColumns(SUPER_ENTITY_COLUMNS);
|
generator.setSuperEntityColumns(SUPER_ENTITY_COLUMNS);
|
||||||
|
generator.setHasWrapper(HAS_WRAPPER);
|
||||||
generator.run();
|
generator.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,19 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.springblade.develop.support;
|
package org.springblade.develop.support;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.DbType;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
import com.baomidou.mybatisplus.generator.config.TemplateType;
|
||||||
import com.baomidou.mybatisplus.generator.config.*;
|
|
||||||
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
|
|
||||||
import com.baomidou.mybatisplus.generator.config.converts.OracleTypeConvert;
|
|
||||||
import com.baomidou.mybatisplus.generator.config.converts.PostgreSqlTypeConvert;
|
|
||||||
import com.baomidou.mybatisplus.generator.config.converts.SqlServerTypeConvert;
|
|
||||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||||
|
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springblade.core.tool.utils.Func;
|
import org.springblade.core.tool.utils.Func;
|
||||||
@ -39,7 +35,9 @@ import org.springframework.core.io.support.PropertiesLoaderUtils;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成器配置类
|
* 代码生成器配置类
|
||||||
@ -52,7 +50,7 @@ public class BladeCodeGenerator {
|
|||||||
/**
|
/**
|
||||||
* 代码所在系统
|
* 代码所在系统
|
||||||
*/
|
*/
|
||||||
private String systemName = DevelopConstant.SWORD_NAME;
|
private String systemName = DevelopConstant.SABER_NAME;
|
||||||
/**
|
/**
|
||||||
* 代码模块名称
|
* 代码模块名称
|
||||||
*/
|
*/
|
||||||
@ -88,11 +86,11 @@ public class BladeCodeGenerator {
|
|||||||
/**
|
/**
|
||||||
* 是否包含基础业务字段
|
* 是否包含基础业务字段
|
||||||
*/
|
*/
|
||||||
private Boolean hasSuperEntity = Boolean.FALSE;
|
private Boolean hasSuperEntity = Boolean.TRUE;
|
||||||
/**
|
/**
|
||||||
* 是否包含包装器
|
* 是否包含包装器
|
||||||
*/
|
*/
|
||||||
private Boolean hasWrapper = Boolean.FALSE;
|
private Boolean hasWrapper = Boolean.TRUE;
|
||||||
/**
|
/**
|
||||||
* 基础业务字段
|
* 基础业务字段
|
||||||
*/
|
*/
|
||||||
@ -101,10 +99,6 @@ public class BladeCodeGenerator {
|
|||||||
* 租户字段
|
* 租户字段
|
||||||
*/
|
*/
|
||||||
private String tenantColumn = "tenant_id";
|
private String tenantColumn = "tenant_id";
|
||||||
/**
|
|
||||||
* 是否启用swagger
|
|
||||||
*/
|
|
||||||
private Boolean isSwagger2 = Boolean.TRUE;
|
|
||||||
/**
|
/**
|
||||||
* 数据库驱动名
|
* 数据库驱动名
|
||||||
*/
|
*/
|
||||||
@ -122,200 +116,138 @@ public class BladeCodeGenerator {
|
|||||||
*/
|
*/
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成执行
|
||||||
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
Properties props = getProperties();
|
Properties props = getProperties();
|
||||||
AutoGenerator mpg = new AutoGenerator();
|
String url = Func.toStr(this.url, props.getProperty("spring.datasource.url"));
|
||||||
GlobalConfig gc = new GlobalConfig();
|
String username = Func.toStr(this.username, props.getProperty("spring.datasource.username"));
|
||||||
String outputDir = getOutputDir();
|
String password = Func.toStr(this.password, props.getProperty("spring.datasource.password"));
|
||||||
String author = props.getProperty("author");
|
|
||||||
gc.setOutputDir(outputDir);
|
|
||||||
gc.setAuthor(author);
|
|
||||||
gc.setFileOverride(true);
|
|
||||||
gc.setOpen(false);
|
|
||||||
gc.setActiveRecord(false);
|
|
||||||
gc.setEnableCache(false);
|
|
||||||
gc.setBaseResultMap(true);
|
|
||||||
gc.setBaseColumnList(true);
|
|
||||||
gc.setMapperName("%sMapper");
|
|
||||||
gc.setXmlName("%sMapper");
|
|
||||||
gc.setServiceName("I%sService");
|
|
||||||
gc.setServiceImplName("%sServiceImpl");
|
|
||||||
gc.setControllerName("%sController");
|
|
||||||
gc.setSwagger2(isSwagger2);
|
|
||||||
mpg.setGlobalConfig(gc);
|
|
||||||
DataSourceConfig dsc = new DataSourceConfig();
|
|
||||||
String driverName = Func.toStr(this.driverName, props.getProperty("spring.datasource.driver-class-name"));
|
|
||||||
if (StringUtil.containsAny(driverName, DbType.MYSQL.getDb())) {
|
|
||||||
dsc.setDbType(DbType.MYSQL);
|
|
||||||
dsc.setTypeConvert(new MySqlTypeConvert());
|
|
||||||
} else if (StringUtil.containsAny(driverName, DbType.POSTGRE_SQL.getDb())) {
|
|
||||||
dsc.setDbType(DbType.POSTGRE_SQL);
|
|
||||||
dsc.setTypeConvert(new PostgreSqlTypeConvert());
|
|
||||||
} else if (StringUtil.containsAny(driverName, DbType.SQL_SERVER.getDb())) {
|
|
||||||
dsc.setDbType(DbType.SQL_SERVER);
|
|
||||||
dsc.setTypeConvert(new SqlServerTypeConvert());
|
|
||||||
} else {
|
|
||||||
dsc.setDbType(DbType.ORACLE);
|
|
||||||
dsc.setTypeConvert(new OracleTypeConvert());
|
|
||||||
}
|
|
||||||
dsc.setDriverName(driverName);
|
|
||||||
dsc.setUrl(Func.toStr(this.url, props.getProperty("spring.datasource.url")));
|
|
||||||
dsc.setUsername(Func.toStr(this.username, props.getProperty("spring.datasource.username")));
|
|
||||||
dsc.setPassword(Func.toStr(this.password, props.getProperty("spring.datasource.password")));
|
|
||||||
mpg.setDataSource(dsc);
|
|
||||||
// 策略配置
|
|
||||||
StrategyConfig strategy = new StrategyConfig();
|
|
||||||
// strategy.setCapitalMode(true);// 全局大写命名
|
|
||||||
// strategy.setDbColumnUnderline(true);//全局下划线命名
|
|
||||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
|
||||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
|
||||||
strategy.setTablePrefix(tablePrefix);
|
|
||||||
if (includeTables.length > 0) {
|
|
||||||
strategy.setInclude(includeTables);
|
|
||||||
}
|
|
||||||
if (excludeTables.length > 0) {
|
|
||||||
strategy.setExclude(excludeTables);
|
|
||||||
}
|
|
||||||
if (hasSuperEntity) {
|
|
||||||
strategy.setSuperEntityClass("org.springblade.core.mp.base.BaseEntity");
|
|
||||||
strategy.setSuperEntityColumns(superEntityColumns);
|
|
||||||
strategy.setSuperServiceClass("org.springblade.core.mp.base.BaseService");
|
|
||||||
strategy.setSuperServiceImplClass("org.springblade.core.mp.base.BaseServiceImpl");
|
|
||||||
} else {
|
|
||||||
strategy.setSuperServiceClass("com.baomidou.mybatisplus.extension.service.IService");
|
|
||||||
strategy.setSuperServiceImplClass("com.baomidou.mybatisplus.extension.service.impl.ServiceImpl");
|
|
||||||
}
|
|
||||||
// 自定义 controller 父类
|
|
||||||
strategy.setSuperControllerClass("org.springblade.core.boot.ctrl.BladeController");
|
|
||||||
strategy.setEntityBuilderModel(false);
|
|
||||||
strategy.setEntityLombokModel(true);
|
|
||||||
strategy.setControllerMappingHyphenStyle(true);
|
|
||||||
mpg.setStrategy(strategy);
|
|
||||||
// 包配置
|
|
||||||
PackageConfig pc = new PackageConfig();
|
|
||||||
// 控制台扫描
|
|
||||||
pc.setModuleName(null);
|
|
||||||
pc.setParent(packageName);
|
|
||||||
pc.setController("controller");
|
|
||||||
pc.setEntity("entity");
|
|
||||||
pc.setXml("mapper");
|
|
||||||
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;
|
||||||
// 自定义配置
|
|
||||||
Map<String, Object> map = new HashMap<>(16);
|
Map<String, Object> customMap = new HashMap<>(11);
|
||||||
InjectionConfig cfg = new InjectionConfig() {
|
customMap.put("codeName", codeName);
|
||||||
@Override
|
customMap.put("serviceName", serviceName);
|
||||||
public void initMap() {
|
customMap.put("servicePackage", servicePackage);
|
||||||
map.put("codeName", codeName);
|
customMap.put("servicePackageLowerCase", servicePackage.toLowerCase());
|
||||||
map.put("serviceName", serviceName);
|
customMap.put("tenantColumn", tenantColumn);
|
||||||
map.put("servicePackage", servicePackage);
|
customMap.put("hasWrapper", hasWrapper);
|
||||||
map.put("servicePackageLowerCase", servicePackage.toLowerCase());
|
Map<String, String> customFile = new HashMap<>(15);
|
||||||
map.put("tenantColumn", tenantColumn);
|
customFile.put("menu.sql", "/templates/sql/menu.sql.vm");
|
||||||
map.put("hasWrapper", hasWrapper);
|
customFile.put("entityVO.java", "/templates/entityVO.java.vm");
|
||||||
this.setMap(map);
|
customFile.put("entityDTO.java", "/templates/entityDTO.java.vm");
|
||||||
}
|
|
||||||
};
|
|
||||||
List<FileOutConfig> focList = new ArrayList<>();
|
|
||||||
focList.add(new FileOutConfig("/templates/sql/menu.sql.vm") {
|
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
map.put("entityKey", (tableInfo.getEntityName().toLowerCase()));
|
|
||||||
map.put("menuId", IdWorker.getId());
|
|
||||||
map.put("addMenuId", IdWorker.getId());
|
|
||||||
map.put("editMenuId", IdWorker.getId());
|
|
||||||
map.put("removeMenuId", IdWorker.getId());
|
|
||||||
map.put("viewMenuId", IdWorker.getId());
|
|
||||||
return getOutputDir() + "/" + "/sql/" + tableInfo.getEntityName().toLowerCase() + ".menu.mysql";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
focList.add(new FileOutConfig("/templates/entityVO.java.vm") {
|
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputDir() + "/" + packageName.replace(".", "/") + "/" + "vo" + "/" + tableInfo.getEntityName() + "VO" + StringPool.DOT_JAVA;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
focList.add(new FileOutConfig("/templates/entityDTO.java.vm") {
|
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputDir() + "/" + packageName.replace(".", "/") + "/" + "dto" + "/" + tableInfo.getEntityName() + "DTO" + StringPool.DOT_JAVA;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (hasWrapper) {
|
if (hasWrapper) {
|
||||||
focList.add(new FileOutConfig("/templates/wrapper.java.vm") {
|
customFile.put("wrapper.java", "/templates/wrapper.java.vm");
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputDir() + "/" + packageName.replace(".", "/") + "/" + "wrapper" + "/" + tableInfo.getEntityName() + "Wrapper" + StringPool.DOT_JAVA;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (Func.isNotBlank(packageWebDir)) {
|
if (Func.isNotBlank(packageWebDir)) {
|
||||||
if (Func.equals(systemName, DevelopConstant.SWORD_NAME)) {
|
if (Func.equals(systemName, DevelopConstant.SWORD_NAME)) {
|
||||||
focList.add(new FileOutConfig("/templates/sword/action.js.vm") {
|
customFile.put("action.js", "/templates/sword/action.js.vm");
|
||||||
@Override
|
customFile.put("model.js", "/templates/sword/model.js.vm");
|
||||||
public String outputFile(TableInfo tableInfo) {
|
customFile.put("service.js", "/templates/sword/service.js.vm");
|
||||||
return getOutputWebDir() + "/actions" + "/" + tableInfo.getEntityName().toLowerCase() + ".js";
|
customFile.put("list.js", "/templates/sword/list.js.vm");
|
||||||
}
|
customFile.put("add.js", "/templates/sword/add.js.vm");
|
||||||
});
|
customFile.put("edit.js", "/templates/sword/edit.js.vm");
|
||||||
focList.add(new FileOutConfig("/templates/sword/model.js.vm") {
|
customFile.put("view.js", "/templates/sword/view.js.vm");
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputWebDir() + "/models" + "/" + tableInfo.getEntityName().toLowerCase() + ".js";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
focList.add(new FileOutConfig("/templates/sword/service.js.vm") {
|
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputWebDir() + "/services" + "/" + tableInfo.getEntityName().toLowerCase() + ".js";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
focList.add(new FileOutConfig("/templates/sword/list.js.vm") {
|
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputWebDir() + "/pages" + "/" + StringUtil.upperFirst(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + ".js";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
focList.add(new FileOutConfig("/templates/sword/add.js.vm") {
|
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputWebDir() + "/pages" + "/" + StringUtil.upperFirst(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "Add.js";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
focList.add(new FileOutConfig("/templates/sword/edit.js.vm") {
|
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputWebDir() + "/pages" + "/" + StringUtil.upperFirst(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "Edit.js";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
focList.add(new FileOutConfig("/templates/sword/view.js.vm") {
|
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputWebDir() + "/pages" + "/" + StringUtil.upperFirst(servicePackage) + "/" + tableInfo.getEntityName() + "/" + tableInfo.getEntityName() + "View.js";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (Func.equals(systemName, DevelopConstant.SABER_NAME)) {
|
} else if (Func.equals(systemName, DevelopConstant.SABER_NAME)) {
|
||||||
focList.add(new FileOutConfig("/templates/saber/api.js.vm") {
|
customFile.put("api.js", "/templates/saber/api.js.vm");
|
||||||
@Override
|
customFile.put("crud.vue", "/templates/saber/crud.vue.vm");
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputWebDir() + "/api" + "/" + servicePackage.toLowerCase() + "/" + tableInfo.getEntityName().toLowerCase() + ".js";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
focList.add(new FileOutConfig("/templates/saber/crud.vue.vm") {
|
|
||||||
@Override
|
|
||||||
public String outputFile(TableInfo tableInfo) {
|
|
||||||
return getOutputWebDir() + "/views" + "/" + servicePackage.toLowerCase() + "/" + tableInfo.getEntityName().toLowerCase() + ".vue";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cfg.setFileOutConfigList(focList);
|
|
||||||
return cfg;
|
FastAutoGenerator.create(url, username, password)
|
||||||
|
.globalConfig(builder -> builder.author(props.getProperty("author")).dateType(DateType.TIME_PACK).enableSwagger().outputDir(getOutputDir()).disableOpenDir())
|
||||||
|
.packageConfig(builder -> builder.parent(packageName).controller("controller").entity("entity").service("service").serviceImpl("service.impl").mapper("mapper").xml("mapper"))
|
||||||
|
.strategyConfig(builder -> builder.addTablePrefix(tablePrefix).addInclude(includeTables).addExclude(excludeTables)
|
||||||
|
.entityBuilder().naming(NamingStrategy.underline_to_camel).columnNaming(NamingStrategy.underline_to_camel).enableLombok().superClass("org.springblade.core.mp.base.BaseEntity").addSuperEntityColumns(superEntityColumns)
|
||||||
|
.serviceBuilder().superServiceClass("org.springblade.core.mp.base.BaseService").superServiceImplClass("org.springblade.core.mp.base.BaseService").formatServiceFileName("I%sService").formatServiceImplFileName("%sServiceImpl")
|
||||||
|
.mapperBuilder().enableMapperAnnotation().enableBaseResultMap().enableBaseColumnList().formatMapperFileName("%sMapper").formatXmlFileName("%sMapper")
|
||||||
|
.controllerBuilder().superClass("org.springblade.core.boot.ctrl.BladeController").formatFileName("%sController").enableRestStyle().enableHyphenStyle()
|
||||||
|
)
|
||||||
|
.templateConfig(builder -> builder.disable(TemplateType.ENTITY)
|
||||||
|
.entity("/templates/entity.java.vm")
|
||||||
|
.service("/templates/service.java.vm")
|
||||||
|
.serviceImpl("/templates/serviceImpl.java.vm")
|
||||||
|
.mapper("/templates/mapper.java.vm")
|
||||||
|
.mapperXml("/templates/mapper.xml.vm")
|
||||||
|
.controller("/templates/controller.java.vm"))
|
||||||
|
.injectionConfig(builder -> builder.beforeOutputFile(
|
||||||
|
(tableInfo, objectMap) -> System.out.println("tableInfo: " + tableInfo.getEntityName() + " objectMap: " + objectMap.size())
|
||||||
|
).customMap(customMap).customFile(customFile)
|
||||||
|
)
|
||||||
|
.templateEngine(new VelocityTemplateEngine() {
|
||||||
|
@Override
|
||||||
|
protected void outputCustomFile(Map<String, String> customFile, TableInfo tableInfo, Map<String, Object> objectMap) {
|
||||||
|
String entityName = tableInfo.getEntityName();
|
||||||
|
String entityNameLower = tableInfo.getEntityName().toLowerCase();
|
||||||
|
|
||||||
|
customFile.forEach((key, value) -> {
|
||||||
|
String outputPath = getPathInfo(OutputFile.other);
|
||||||
|
if (StringUtil.equals(key, "menu.sql")) {
|
||||||
|
objectMap.put("entityKey", entityNameLower);
|
||||||
|
objectMap.put("menuId", IdWorker.getId());
|
||||||
|
objectMap.put("addMenuId", IdWorker.getId());
|
||||||
|
objectMap.put("editMenuId", IdWorker.getId());
|
||||||
|
objectMap.put("removeMenuId", IdWorker.getId());
|
||||||
|
objectMap.put("viewMenuId", IdWorker.getId());
|
||||||
|
outputPath = getOutputDir() + StringPool.SLASH + "sql" + StringPool.SLASH + entityNameLower + ".menu.sql";
|
||||||
|
}
|
||||||
|
if (StringUtil.equals(key, "entityVO.java")) {
|
||||||
|
outputPath = getOutputDir() + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH + "vo" + StringPool.SLASH + entityName + "VO" + StringPool.DOT_JAVA;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "entityDTO.java")) {
|
||||||
|
outputPath = getOutputDir() + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH + "dto" + StringPool.SLASH + entityName + "DTO" + StringPool.DOT_JAVA;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "wrapper.java")) {
|
||||||
|
outputPath = getOutputDir() + StringPool.SLASH + packageName.replace(StringPool.DOT, StringPool.SLASH) + StringPool.SLASH + "wrapper" + StringPool.SLASH + entityName + "Wrapper" + StringPool.DOT_JAVA;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "action.js")) {
|
||||||
|
outputPath = getOutputWebDir() + StringPool.SLASH + "actions" + StringPool.SLASH + entityNameLower + ".js";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "model.js")) {
|
||||||
|
outputPath = getOutputWebDir() + StringPool.SLASH + "models" + StringPool.SLASH + entityNameLower + ".js";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "service.js")) {
|
||||||
|
outputPath = getOutputWebDir() + StringPool.SLASH + "services" + StringPool.SLASH + entityNameLower + ".js";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "list.js")) {
|
||||||
|
outputPath = getOutputWebDir() + StringPool.SLASH + "pages" + StringPool.SLASH + StringUtil.upperFirst(servicePackage) + StringPool.SLASH + entityName + StringPool.SLASH + entityName + ".js";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "add.js")) {
|
||||||
|
outputPath = getOutputWebDir() + StringPool.SLASH + "pages" + StringPool.SLASH + StringUtil.upperFirst(servicePackage) + StringPool.SLASH + entityName + StringPool.SLASH + entityName + "Add.js";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "edit.js")) {
|
||||||
|
outputPath = getOutputWebDir() + StringPool.SLASH + "pages" + StringPool.SLASH + StringUtil.upperFirst(servicePackage) + StringPool.SLASH + entityName + StringPool.SLASH + entityName + "Edit.js";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "view.js")) {
|
||||||
|
outputPath = getOutputWebDir() + StringPool.SLASH + "pages" + StringPool.SLASH + StringUtil.upperFirst(servicePackage) + StringPool.SLASH + entityName + StringPool.SLASH + entityName + "View.js";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "api.js")) {
|
||||||
|
outputPath = getOutputWebDir() + StringPool.SLASH + "api" + StringPool.SLASH + servicePackage.toLowerCase() + StringPool.SLASH + entityNameLower + ".js";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.equals(key, "crud.vue")) {
|
||||||
|
outputPath = getOutputWebDir() + StringPool.SLASH + "views" + StringPool.SLASH + servicePackage.toLowerCase() + StringPool.SLASH + entityNameLower + ".vue";
|
||||||
|
}
|
||||||
|
outputFile(new File(String.valueOf(outputPath)), objectMap, value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取配置文件
|
* 获取配置文件
|
||||||
*
|
*
|
||||||
@ -351,17 +283,4 @@ public class BladeCodeGenerator {
|
|||||||
return (Func.isBlank(packageWebDir) ? System.getProperty("user.dir") : packageWebDir) + "/src";
|
return (Func.isBlank(packageWebDir) ? System.getProperty("user.dir") : packageWebDir) + "/src";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 页面生成的文件名
|
|
||||||
*/
|
|
||||||
private String getGeneratorViewPath(String viewOutputDir, TableInfo tableInfo, String suffixPath) {
|
|
||||||
String name = StringUtils.firstToLowerCase(tableInfo.getEntityName());
|
|
||||||
String path = viewOutputDir + "/" + name + "/" + name + suffixPath;
|
|
||||||
File viewDir = new File(path).getParentFile();
|
|
||||||
if (!viewDir.exists()) {
|
|
||||||
viewDir.mkdirs();
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ import $!{superControllerClassPackage};
|
|||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RequestMapping("#if($!{package.ModuleName})/$!{package.ModuleName}#end/$!{cfg.entityKey}")
|
@RequestMapping("#if($!{package.ModuleName})$!{package.ModuleName}#end/$!{entityKey}")
|
||||||
@Api(value = "$!{table.comment}", tags = "$!{table.comment}接口")
|
@Api(value = "$!{table.comment}", tags = "$!{table.comment}接口")
|
||||||
#if($!{superControllerClass})
|
#if($!{superControllerClass})
|
||||||
public class $!{table.controllerName} extends $!{superControllerClass} {
|
public class $!{table.controllerName} extends $!{superControllerClass} {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
|
INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
|
||||||
VALUES ('$!{cfg.menuId}', 1123598815738675201, '$!{cfg.entityKey}', '$!{cfg.codeName}', 'menu', '/$!{cfg.servicePackage}/$!{cfg.entityKey}', NULL, 1, 1, 0, 1, NULL, 0);
|
VALUES ('$!{menuId}', 1123598815738675201, '$!{entityKey}', '$!{codeName}', 'menu', '/$!{servicePackage}/$!{entityKey}', NULL, 1, 1, 0, 1, NULL, 0);
|
||||||
INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
|
INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
|
||||||
VALUES ('$!{cfg.addMenuId}', '$!{cfg.menuId}', '$!{cfg.entityKey}_add', '新增', 'add', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/add', 'plus', 1, 2, 1, 1, NULL, 0);
|
VALUES ('$!{addMenuId}', '$!{menuId}', '$!{entityKey}_add', '新增', 'add', '/$!{servicePackage}/$!{entityKey}/add', 'plus', 1, 2, 1, 1, NULL, 0);
|
||||||
INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
|
INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
|
||||||
VALUES ('$!{cfg.editMenuId}', '$!{cfg.menuId}', '$!{cfg.entityKey}_edit', '修改', 'edit', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/edit', 'form', 2, 2, 2, 1, NULL, 0);
|
VALUES ('$!{editMenuId}', '$!{menuId}', '$!{entityKey}_edit', '修改', 'edit', '/$!{servicePackage}/$!{entityKey}/edit', 'form', 2, 2, 2, 1, NULL, 0);
|
||||||
INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
|
INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
|
||||||
VALUES ('$!{cfg.removeMenuId}', '$!{cfg.menuId}', '$!{cfg.entityKey}_delete', '删除', 'delete', '/api/$!{cfg.serviceName}/$!{cfg.entityKey}/remove', 'delete', 3, 2, 3, 1, NULL, 0);
|
VALUES ('$!{removeMenuId}', '$!{menuId}', '$!{entityKey}_delete', '删除', 'delete', '/api/$!{serviceName}/$!{entityKey}/remove', 'delete', 3, 2, 3, 1, NULL, 0);
|
||||||
INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
|
INSERT INTO `blade_menu`(`id`, `parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
|
||||||
VALUES ('$!{cfg.viewMenuId}', '$!{cfg.menuId}', '$!{cfg.entityKey}_view', '查看', 'view', '/$!{cfg.servicePackage}/$!{cfg.entityKey}/view', 'file-text', 4, 2, 2, 1, NULL, 0);
|
VALUES ('$!{viewMenuId}', '$!{menuId}', '$!{entityKey}_view', '查看', 'view', '/$!{servicePackage}/$!{entityKey}/view', 'file-text', 4, 2, 2, 1, NULL, 0);
|
||||||
|
4
pom.xml
4
pom.xml
@ -43,8 +43,8 @@
|
|||||||
<swagger.version>2.10.5</swagger.version>
|
<swagger.version>2.10.5</swagger.version>
|
||||||
<swagger.models.version>1.6.2</swagger.models.version>
|
<swagger.models.version>1.6.2</swagger.models.version>
|
||||||
<knife4j.version>2.0.9</knife4j.version>
|
<knife4j.version>2.0.9</knife4j.version>
|
||||||
<mybatis.plus.version>3.4.3.4</mybatis.plus.version>
|
<mybatis.plus.version>3.5.1</mybatis.plus.version>
|
||||||
<mybatis.plus.generator.version>3.4.1</mybatis.plus.generator.version>
|
<mybatis.plus.generator.version>3.5.1</mybatis.plus.generator.version>
|
||||||
<protostuff.version>1.6.0</protostuff.version>
|
<protostuff.version>1.6.0</protostuff.version>
|
||||||
<disruptor.version>3.4.2</disruptor.version>
|
<disruptor.version>3.4.2</disruptor.version>
|
||||||
<guava.version>20.0</guava.version>
|
<guava.version>20.0</guava.version>
|
||||||
|
Loading…
Reference in New Issue
Block a user