- 配置对应依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.5.2</version>
</dependency>
<!-- 引入mybatis-plus-generator依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
<version>2.7.0</version>
</dependency>
2.生成代码,可以直接生成使用
public static void main(String[] args) {
//设置表名
List<String> tableList = Arrays.asList("admdvs_info_a");
FastAutoGenerator.create("url", "username", "password")
.globalConfig(builder -> {
builder.author("baomidou") // 设置作者
// .enableSwagger() // 开启 swagger 模式
.outputDir("D:\\MyBatis-Generator\\src\\main\\java"); // 指定输出目录
})
.packageConfig(builder -> {
builder.parent("com.example.generator.local") // 设置父包名
.entity("pojo");//设置实体包名
})
.strategyConfig(builder -> {
builder.addInclude(tableList)
.controllerBuilder()
.entityBuilder()
//开启Lombok
.enableLombok()
.addTableFills(new Column("CRT_TIME",FieldFill.INSERT),
new Column("UPD_TIME",FieldFill.INSERT_UPDATE))
;
})
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
}