1.添加依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
2.在入口函数中生成代码
public static void main(String[] args) {
generate();
//SpringApplication.run(Programe.class);
}
private static void generate(){
FastAutoGenerator.create("jdbc:mysql://localhost:3685/uniosdb?characterEncoding=utf8&serverTimezone=UTC", "unios_user", "UniOS_001")
.globalConfig(builder -> {
builder.author("el") // 设置作者
//.enableSwagger() // 开启 swagger 模式
.fileOverride() // 覆盖已生成文件
.outputDir("E:\\02test\\ja\\studentdemo1\\src\\main\\java\\testmapper"); // 指定输出目录
})
.packageConfig(builder -> {
builder.parent("com.el.springboot") // 设置父包名
.moduleName(null) // 设置父包模块名 路径
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E:\\02test\\ja\\studentdemo1\\src\\main\\resources\\testmapper")); // 设置mapperXml生成路径
})
.strategyConfig(builder -> {
builder.entityBuilder().enableLombok();//Lombok表达式
builder.mapperBuilder().enableMapperAnnotation().build();//加mapper注解
builder.controllerBuilder().enableHyphenStyle() // 开启驼峰转连字符
.enableRestStyle(); // 开启生成@RestController 控制器
builder.addInclude("sys_user")
.addInclude("a_blog")
.addInclude("a_role")
.addInclude("a_user_ext")// 设置需要生成的表名
.addTablePrefix("a_","t_", "sys_"); // 设置过滤表前缀
})
//.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
}