优化
This commit is contained in:
parent
2ed21eacc7
commit
76dc441444
@ -22,6 +22,8 @@ dependencies {
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.20'
|
||||
implementation 'org.yaml:snakeyaml:1.33'
|
||||
implementation 'org.apache.commons:commons-lang3:3.12.0'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.22'
|
||||
|
||||
|
||||
//mybatis plus gen
|
||||
// implementation 'org.springframework.boot:spring-boot-starter'
|
||||
|
||||
@ -41,6 +41,10 @@ public class Config {
|
||||
* 包名
|
||||
*/
|
||||
private String packageName;
|
||||
/**
|
||||
* 基础包
|
||||
*/
|
||||
private String basePackage;
|
||||
/**
|
||||
* 项目名
|
||||
*/
|
||||
|
||||
@ -179,47 +179,54 @@ public class GeneratorUtil {
|
||||
* 生成实体
|
||||
*/
|
||||
public static void generatorCode(List<Column> list, String tableName) {
|
||||
generatorByTemplate(list,tableName,"po");
|
||||
generatorByTemplate(list,tableName,"entity");
|
||||
generatorByTemplate(list,tableName,"resDto");
|
||||
generatorByTemplate(list,tableName,"reqDto");
|
||||
// generatorByTemplate(list,tableName,"po");
|
||||
// generatorByTemplate(list,tableName,"entity");
|
||||
// generatorByTemplate(list,tableName,"resDto");
|
||||
// generatorByTemplate(list,tableName,"reqDto");
|
||||
// generatorByTemplate(list,tableName,"repository");
|
||||
// generatorByTemplate(list,tableName,"service");
|
||||
generatorByTemplate(null,tableName,"mapper");
|
||||
// generatorByTemplate(null,tableName,"mapper");
|
||||
generatorByTemplate(null, tableName, "mapper.xml");
|
||||
// generatorByTemplate(list,tableName,"controller");
|
||||
}
|
||||
|
||||
// public static void generatorPo_bak(List<Column> list, String table) throws IOException, TemplateException {
|
||||
// //如果有前缀去除
|
||||
// String className = table;
|
||||
// if (StringUtils.isNotEmpty(CONFIG.getTablePrefix())) {
|
||||
// className = formatTableName(table);
|
||||
// }
|
||||
// // 类名首字母大写
|
||||
// className = toUpperCaseFist(className);
|
||||
// Configuration configuration = new Configuration(Configuration.VERSION_2_3_0);
|
||||
// Template template = configuration.getTemplate("src/main/resources/template/po.ftl");
|
||||
// String path = CONFIG.getProjectName() + "-server/" + package2Path(CONFIG.getPackageName() + ".infrastructure.persistence.po/");
|
||||
// String filepath = path + className + SUFFIX;
|
||||
// // 文件夹不存在创建
|
||||
// if (!new File(path).exists()) {
|
||||
// if (new File(path).mkdirs()) {
|
||||
// // System.out.println("PO 文件夹创建成功");
|
||||
// }
|
||||
// if (new File(filepath).createNewFile()) {
|
||||
// System.out.println("=== PO:[" + className + " ] 创建成功 ===");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// Map<String, Object> data = new HashMap<>();
|
||||
// data.put("package", CONFIG.getPackageName() + ".infrastructure.persistence.po");
|
||||
// data.put("table_name", table);
|
||||
// data.put("class_name", className);
|
||||
// data.put("columns", list);
|
||||
// File file = new File(filepath);
|
||||
// template.process(data, new FileWriter(file));
|
||||
// }
|
||||
|
||||
/**
|
||||
* 生成文件
|
||||
*
|
||||
* @param columnList 列
|
||||
* @param table 表名
|
||||
* @param type 类型
|
||||
*/
|
||||
public static void generatorByTemplate(List<Column> columnList, String table, TypeEnum type) {
|
||||
// 文件模板路径
|
||||
String templatePath = String.format("src/main/resources/template/%s.ftl", type.getTemplate());
|
||||
String destPath = null;
|
||||
String projectName = CONFIG.getProjectName();
|
||||
// 去除前缀
|
||||
String className = formatTableName(table);
|
||||
// 转换为大驼峰式命名
|
||||
className = toUpperCaseFist(toCamelCase(className));
|
||||
String baseMapperXml = "%s-%s/src/main/resources/mapper/%s%s.xml";
|
||||
String baseClassFile = "%s-%s/src/main/java/%s/%s/%s%s.java";
|
||||
switch (type) {
|
||||
case MAPPER_XML:
|
||||
destPath = String.format(baseMapperXml, projectName, type.getModule(), className, toUpperCaseFist(type.getTemplate()));
|
||||
break;
|
||||
case RES_DTO:
|
||||
destPath = String.format(baseClassFile, projectName, type.getModule(),
|
||||
package2Path(CONFIG.getPackageName()),
|
||||
package2Path(CONFIG.getPackageLocation().getResDto()),
|
||||
className, toUpperCaseFist(type.getTemplate()));
|
||||
|
||||
case REQ_DTO:
|
||||
destPath = String.format(baseClassFile, projectName, type.getModule(), package2Path(CONFIG.getPackageName()), package2Path(CONFIG.getPackageLocation().getReqDto()));
|
||||
|
||||
default:
|
||||
destPath = String.format(baseClassFile, projectName, type.getModule(), package2Path(CONFIG.getPackageName()), package2Path(""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* create template file
|
||||
|
||||
@ -14,6 +14,7 @@ public enum TypeEnum {
|
||||
DOMAIN_SERVICE("领域服务", "domainService", "server"),
|
||||
APPLICATION_SERVICE("应用层", "applicationService", "server"),
|
||||
MAPPER("DAO", "mapper", "server"),
|
||||
MAPPER_XML("XML","mapper.xml", "server"),
|
||||
REPOSITORY("仓储层", "repository", "server"),
|
||||
ENTITY("领域实体", "entity", "server"),
|
||||
RES_DTO("响应体", "resDto", "dto"),
|
||||
|
||||
@ -11,6 +11,8 @@ generate:
|
||||
url: jdbc:postgresql://db.timemail.email:5432/timemail
|
||||
# 包名
|
||||
packageName: cn.timemail.email
|
||||
# 项目基础包
|
||||
basePackage: timemail.email
|
||||
# 项目名称
|
||||
projectName: timemail
|
||||
# 前缀
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
package cn.rainss.codegenerator;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class CodeGeneratorApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user