codeGenerator修改
This commit is contained in:
父節點
0f239f7978
當前提交
6cb64ca442
@ -1,68 +0,0 @@
|
||||
package com.cnbm.generator.build;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.cnbm.generator.config.DataConfig;
|
||||
import com.cnbm.generator.engine.EnhanceVelocityTemplateEngine;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author weihongyang
|
||||
* @Date 2022/6/14 8:47 AM
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class CodeGenerator {
|
||||
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
mybatisPlusGenerator(new String[]{"sys_user","sys_role"});
|
||||
}
|
||||
|
||||
public static void mybatisPlusGenerator(String[] include){
|
||||
File file = new File("");
|
||||
String path = file.getAbsolutePath();
|
||||
Map<String, String> customFile = new HashMap<>();
|
||||
customFile.put("DTO","/templates/DTO.java.vm");
|
||||
customFile.put("Excel","/templates/Excel.java.vm");
|
||||
customFile.put("mysql","/templates/mysql.vm");
|
||||
|
||||
|
||||
FastAutoGenerator.create(DataConfig.url,DataConfig.username,DataConfig.password)
|
||||
.globalConfig(builder -> {
|
||||
builder.author("why")
|
||||
.enableSwagger()
|
||||
.fileOverride()
|
||||
.outputDir(path+"/src/main/java");
|
||||
})
|
||||
.packageConfig(builder -> {
|
||||
//设置父包名
|
||||
builder.parent("com.cnbm.generator")
|
||||
.moduleName("code")
|
||||
.service("service")
|
||||
.serviceImpl("service.impl")
|
||||
.entity("entity")
|
||||
.mapper("mapper")
|
||||
.controller("controller")
|
||||
.xml("mapper");
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
//设置需要生成的表名
|
||||
builder.addInclude(include)
|
||||
//设置过滤表前缀
|
||||
.addTablePrefix("sys_")
|
||||
//添加逻辑删除列
|
||||
.entityBuilder().logicDeleteColumnName("valid").build();
|
||||
})
|
||||
.injectionConfig(consumer -> {
|
||||
|
||||
consumer.customFile(customFile);
|
||||
})
|
||||
.templateEngine(new EnhanceVelocityTemplateEngine())
|
||||
.execute();
|
||||
}
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package com.cnbm.generator.engine;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
|
||||
import com.cnbm.generator.utils.IdWorker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author weihongyang
|
||||
* @Date 2022/6/17 10:27 AM
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class EnhanceVelocityTemplateEngine extends VelocityTemplateEngine {
|
||||
@Override
|
||||
protected void outputCustomFile(@NotNull Map<String, String> customFile, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
|
||||
String entityName = tableInfo.getEntityName();
|
||||
System.out.println(entityName);
|
||||
// String otherPath = this.getPathInfo(OutputFile.other);
|
||||
File file = new File("");
|
||||
String path = file.getAbsolutePath();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
objectMap.put("id"+ i, IdWorker.getId());
|
||||
}
|
||||
customFile.forEach((key, value) -> {
|
||||
String fileName = "";
|
||||
if ("DTO".equals(key)) {
|
||||
fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator/code"+ File.separator + "dto" + File.separator + entityName + "%s" + ".java"), key);
|
||||
}
|
||||
if ("Excel".equals(key)) {
|
||||
fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator/code"+ File.separator + "excel" + File.separator + entityName + "%s" + ".java"), key);
|
||||
}
|
||||
if ("mysql".equals(key)) {
|
||||
fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator/code"+ File.separator + "mysql" + File.separator + entityName + "%s" + ".sql"), key);
|
||||
}
|
||||
this.outputFile(new File(fileName), objectMap, value);
|
||||
});
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void writer(Map<String, Object> objectMap, String templatePath, File outputFile) throws Exception {
|
||||
// // 获取table
|
||||
// TableInfo tableInfo = (TableInfo) objectMap.get("table");
|
||||
// // 取出Service接口的名字,进行首字母小写处理
|
||||
// String serviceNameFirstWord = tableInfo.getServiceName().substring(0,1).toLowerCase();
|
||||
// String serviceNameFirstWordToLower = serviceNameFirstWord + tableInfo.getServiceName().substring(1);
|
||||
// objectMap.put("serviceNameFirstWordToLower", serviceNameFirstWordToLower);
|
||||
//
|
||||
// // 取出mapper接口的名字,进行首字母小写处理
|
||||
// String mapperNameFirstWord = tableInfo.getMapperName().substring(0, 1).toLowerCase();
|
||||
// String mapperNameFirstWordToLower = mapperNameFirstWord + tableInfo.getMapperName().substring(1);
|
||||
// objectMap.put("mapperNameFirstWordToLower", mapperNameFirstWordToLower);
|
||||
//
|
||||
// // 对Form、VO文件的处理
|
||||
//// new FormHandler().handler(objectMap);
|
||||
// super.writer(objectMap, templatePath, outputFile);
|
||||
// }
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user