初始化
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.njcn.autocode.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* 需要生成代码的模块
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年12月10日 16:03
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Module implements Serializable {
|
||||
|
||||
private String author;
|
||||
|
||||
private String packageName;
|
||||
|
||||
private String moduleName;
|
||||
|
||||
private List<String> tableNames;
|
||||
|
||||
private String prefix;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.njcn.autocode.utils;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||
import com.baomidou.mybatisplus.generator.config.po.LikeTable;
|
||||
import com.njcn.autocode.pojo.Module;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年12月10日 15:16
|
||||
*/
|
||||
public class GenerateCode {
|
||||
|
||||
private static final String TARGET_DIR = "D://code";
|
||||
|
||||
private static final String DB_URL = "jdbc:mysql://192.168.1.14:13306/pqsinfo";
|
||||
|
||||
private static final String USERNAME = "root";
|
||||
|
||||
private static final String PASSWORD = "njcnpqs";
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Module> modules = Stream.of(
|
||||
new Module("hongawen", "com.njcn", "user", Stream.of(
|
||||
"sys_component"
|
||||
,"sys_dept"
|
||||
,"sys_function"
|
||||
,"sys_home_page"
|
||||
,"sys_role"
|
||||
,"sys_role_component"
|
||||
,"sys_role_function"
|
||||
,"sys_user"
|
||||
,"sys_user_role"
|
||||
,"sys_user_set"
|
||||
,"sys_auth_client"
|
||||
,"sys_user_strategy"
|
||||
).collect(Collectors.toList()), "sys_")
|
||||
, new Module("hongawen", "com.njcn", "system", Stream.of(
|
||||
"sys_dict_data"
|
||||
,"sys_area"
|
||||
,"sys_config"
|
||||
,"sys_dict_type"
|
||||
,"sys_task"
|
||||
,"sys_resource"
|
||||
,"sys_theme"
|
||||
).collect(Collectors.toList()), "sys_")
|
||||
).collect(Collectors.toList());
|
||||
generateJavaFile(modules);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量生成不同模块的代码
|
||||
* @param modules 模块数据
|
||||
*/
|
||||
private static void generateJavaFile(List<Module> modules) {
|
||||
for (Module module : modules) {
|
||||
//文件夹提前建好,否则会报错
|
||||
FastAutoGenerator.create(DB_URL, USERNAME, PASSWORD)
|
||||
.globalConfig(builder -> {
|
||||
builder.author(module.getAuthor()) // 设置作者
|
||||
.fileOverride() // 覆盖已生成文件
|
||||
.outputDir(TARGET_DIR); // 指定输出目录
|
||||
})
|
||||
.packageConfig(builder -> {
|
||||
builder.parent(module.getPackageName()) // 设置父包名
|
||||
.moduleName(module.getModuleName()) // 设置父包模块名
|
||||
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, TARGET_DIR+ File.separator+module.getModuleName())); // 设置mapperXml生成路径
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
builder.addInclude(module.getTableNames()) // 设置需要生成的表名
|
||||
.addTablePrefix(module.getPrefix())// 设置过滤表前缀
|
||||
.entityBuilder()
|
||||
.superClass(com.njcn.db.bo.BaseEntity.class) //默认实体继承指定父类
|
||||
.enableLombok() //启用lombok
|
||||
.controllerBuilder()
|
||||
.superClass(com.njcn.web.controller.BaseController.class) //默认controller继承指定父类
|
||||
.enableRestStyle() //开启生成@RestController 控制器
|
||||
;
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user