|
@@ -0,0 +1,73 @@
|
|
|
|
+package com.alvin;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
|
|
+import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
|
|
|
+import com.baomidou.mybatisplus.generator.config.OutputFile;
|
|
|
|
+import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
|
|
|
+import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
|
|
|
+import com.baomidou.mybatisplus.generator.fill.Column;
|
|
|
|
+
|
|
|
|
+import java.util.Collections;
|
|
|
|
+
|
|
|
|
+public class Generator {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ String db_url = "jdbc:mysql://localhost:3306/aj_report";
|
|
|
|
+ String db_username = "root";
|
|
|
|
+ String db_password = "root";
|
|
|
|
+
|
|
|
|
+ String javaDir = "C:/code";
|
|
|
|
+ String parentPackage = "com.alvin.db";
|
|
|
|
+ String tableName = "access_role";
|
|
|
|
+
|
|
|
|
+ String author = "tianyun";
|
|
|
|
+ String tablePrefix = "t_";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ generatorToFile(db_url, db_username, db_password, author, javaDir, parentPackage, tableName, tablePrefix);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void generatorToFile(String db_url, String db_username, String db_password, String author,
|
|
|
|
+ String javaDir, String parentPackage, String tableName, String tablePrefix) {
|
|
|
|
+ FastAutoGenerator.create(db_url, db_username, db_password)
|
|
|
|
+ //===全局配置
|
|
|
|
+ .globalConfig(builder -> {
|
|
|
|
+ builder.author(author) // 设置作者
|
|
|
|
+ .dateType(DateType.ONLY_DATE) // 设置日期为 Date
|
|
|
|
+ //.enableSwagger() // 开启 swagger 模式
|
|
|
|
+ .fileOverride() // 覆盖已生成文件
|
|
|
|
+ .outputDir(javaDir); // 指定输出目录
|
|
|
|
+ })
|
|
|
|
+ //===模块配置
|
|
|
|
+ .packageConfig(builder -> {
|
|
|
|
+ builder.parent(parentPackage) // 设置父包名
|
|
|
|
+ .moduleName("") // 设置父包模块名
|
|
|
|
+ .pathInfo(Collections.singletonMap(OutputFile.mapperXml, javaDir + "/../resources/mapper")); // 设置mapperXml生成路径
|
|
|
|
+ })
|
|
|
|
+ .strategyConfig(builder -> {
|
|
|
|
+ //Controller
|
|
|
|
+ builder.controllerBuilder().enableHyphenStyle() // 开启驼峰转连字符
|
|
|
|
+ .enableRestStyle(); // 开启生成@RestController 控制器
|
|
|
|
+ //mapper
|
|
|
|
+ builder.mapperBuilder().enableMapperAnnotation().build();
|
|
|
|
+ //实体类
|
|
|
|
+ builder.entityBuilder()
|
|
|
|
+ .enableLombok()
|
|
|
|
+ .addTableFills(
|
|
|
|
+ new Column("create_time", FieldFill.INSERT),
|
|
|
|
+ new Column("update_time", FieldFill.INSERT_UPDATE)
|
|
|
|
+ );
|
|
|
|
+ builder.addInclude(tableName) // 设置需要生成的表名
|
|
|
|
+ .addTablePrefix(tablePrefix)
|
|
|
|
+
|
|
|
|
+ ;
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+ .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
|
|
|
|
+ .templateConfig(builder -> builder.controller("templates/controller1.java")) // 设置为空则不会生成该文件
|
|
|
|
+ //.templateConfig(builder -> builder.service(""))
|
|
|
|
+ .templateConfig(builder -> builder.serviceImpl("templates/serviceImpl1.java"))
|
|
|
|
+ .execute();
|
|
|
|
+ }
|
|
|
|
+}
|