初始化
This commit is contained in:
42
pqs-common/common-autocode/pom.xml
Normal file
42
pqs-common/common-autocode/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>pqs-common</artifactId>
|
||||
<groupId>com.njcn</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>common-autocode</artifactId>
|
||||
<!--所有的代码生成完毕后,请按需拷贝到相应的服务模块中-->
|
||||
<name>mybatis-plus代码自动生成模块</name>
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-db</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-web</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<!-- mybatis-plus自动生成代码 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
</dependency>
|
||||
<!--模板引起,mp默认支持的velocity也可以切换为freemarker-->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -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