直接点击运行
/**
* 代码自动生成
*/
public class CodeGenerate {
/**
* 执行 run
*/
public static void main(String[] args) throws SQLException {
//开发环境测试库用于库表相关代码自动生成,没有数据
String url = "jdbc:mysql://127.0.0.1:3306/test";
String username = "root";
String password = "root";
String projectPath = System.getProperty("user.dir");
// 指定输出目录
String outputDir = projectPath + "/src/main/java/";
// 设置作者
String author = "wck";
// 设置父包名
String parent = "com.wck";
// 设置mapperXml生成路径
String mapperPath = projectPath + "/src/main/resources/mapper";
// 设置需要生成的表名
String table = "数据库表名称";
// 设置过滤表前缀
// String[] prefixArr = {"a_", "b_"};
FastAutoGenerator.create(url, username, password)
.globalConfig(builder -> builder.author(author).outputDir(outputDir).commentDate(DatePattern.NORM_DATETIME_MINUTE_PATTERN))
.packageConfig(builder -> builder.parent(parent).pathInfo(Collections.singletonMap(OutputFile.xml, mapperPath)))
.strategyConfig(builder -> builder
.addInclude(table)
// .addTablePrefix(prefixArr)
.controllerBuilder().enableFileOverride().enableRestStyle()
.serviceBuilder().enableFileOverride()
.entityBuilder().enableFileOverride().enableLombok()
.mapperBuilder().enableFileOverride())
.templateEngine(new FreemarkerTemplateEngine())
.execute();
}
}