|
@@ -7,34 +7,43 @@ import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
|
|
public class Generator {
|
|
public class Generator {
|
|
|
|
+
|
|
|
|
+
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
String db_url = "jdbc:mysql://localhost:3306/aj_report";
|
|
String db_url = "jdbc:mysql://localhost:3306/aj_report";
|
|
String db_username = "root";
|
|
String db_username = "root";
|
|
String db_password = "root";
|
|
String db_password = "root";
|
|
|
|
|
|
- String author = "tianyun";
|
|
|
|
- String outputDir = "c:/code";
|
|
|
|
|
|
+ String javaDir = "C:\\Users\\root\\IdeaProjects\\java-base-maven\\mybatis-test\\src\\main\\java";
|
|
String parentPackage = "com.alvin";
|
|
String parentPackage = "com.alvin";
|
|
- String moduleName = "user";
|
|
|
|
|
|
+ String moduleName = "db";
|
|
|
|
+ String tableName = "access_role";
|
|
|
|
+
|
|
|
|
+ String author = "tianyun";
|
|
|
|
+ String tablePrefix = "t_";
|
|
|
|
|
|
|
|
+
|
|
|
|
+ generatorToFile(db_url, db_username, db_password, author, javaDir, parentPackage, moduleName, tableName, tablePrefix);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void generatorToFile(String db_url, String db_username, String db_password, String author, String javaDir, String parentPackage, String moduleName, String tableName, String tablePrefix) {
|
|
FastAutoGenerator.create(db_url, db_username, db_password)
|
|
FastAutoGenerator.create(db_url, db_username, db_password)
|
|
.globalConfig(builder -> {
|
|
.globalConfig(builder -> {
|
|
builder.author(author) // 设置作者
|
|
builder.author(author) // 设置作者
|
|
- .enableSwagger() // 开启 swagger 模式
|
|
|
|
|
|
+ //.enableSwagger() // 开启 swagger 模式
|
|
.fileOverride() // 覆盖已生成文件
|
|
.fileOverride() // 覆盖已生成文件
|
|
- .outputDir(outputDir); // 指定输出目录
|
|
|
|
|
|
+ .outputDir(javaDir); // 指定输出目录
|
|
})
|
|
})
|
|
.packageConfig(builder -> {
|
|
.packageConfig(builder -> {
|
|
builder.parent(parentPackage) // 设置父包名
|
|
builder.parent(parentPackage) // 设置父包名
|
|
.moduleName(moduleName) // 设置父包模块名
|
|
.moduleName(moduleName) // 设置父包模块名
|
|
- .pathInfo(Collections.singletonMap(OutputFile.mapperXml, outputDir)); // 设置mapperXml生成路径
|
|
|
|
|
|
+ .pathInfo(Collections.singletonMap(OutputFile.mapperXml, javaDir + "/../resources/mapper")); // 设置mapperXml生成路径
|
|
})
|
|
})
|
|
.strategyConfig(builder -> {
|
|
.strategyConfig(builder -> {
|
|
- builder.addInclude("access_role") // 设置需要生成的表名
|
|
|
|
- .addTablePrefix("t_", "c_"); // 设置过滤表前缀
|
|
|
|
|
|
+ builder.addInclude(tableName) // 设置需要生成的表名
|
|
|
|
+ .addTablePrefix(tablePrefix); // 设置过滤表前缀
|
|
})
|
|
})
|
|
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
|
|
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
|
|
.execute();
|
|
.execute();
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|