Mybatis-Plus代码生成器

1. 引入依赖

XML 复制代码
        <!-- 代码生成器,逆向工程 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.31</version>
        </dependency>

2. 快速生成

java 复制代码
@SpringBootTest
public class FastAutoGeneratorTest {
    /**
     * 快速生成代码
     */
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/mybatis_plus? characterEncoding=utf-8&userSSL=false", "root", "1234")
                .globalConfig(builder -> {
                    builder.author("kk") // 设置作者
                            //.enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D://MBP"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.qcby.mbp") // 设置父包名
                            .moduleName("mybatisplus") // 设置父包模块名
                            //.pathMapping("/", "D://MBP"); // 设置mapperXml生成路径
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://MBP"));  // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("t_user") // 设置需要生成的表名
                            .addTablePrefix("t_", "c_"); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
                .execute();
    }
}
相关推荐
憧憬成为web高手13 小时前
皮卡丘靶场速通--sql 2
数据库·sql·mybatis
Java面试题总结2 天前
mybatis插件
java·tomcat·mybatis
Devin~Y3 天前
互联网大厂Java面试实战:Spring Boot、MyBatis、Redis、Kafka、JWT、Spring Cloud 与 AI 场景追问
java·spring boot·redis·spring cloud·kafka·mybatis·spring security
Ethan01073 天前
mybatis插件
mybatis
扎Zn了老Fe4 天前
MyBatis-Plus必知必会:告别低效CRUD,高效开发持久层
后端·mybatis
醉城夜风~4 天前
MyBatis 基础CRUD全套实战学习笔记
笔记·学习·mybatis
万亿少女的梦1684 天前
基于微信小程序、Spring Boot与Vue3的智慧养老管理系统设计与实现
spring boot·redis·微信小程序·mybatis·vue3
4154115 天前
MyBatis-Plus + PostGIS 实战(四):GeoJSON 序列化与前端地图对接,全局 WKT + 局部 GeoJSON,两种格式优雅共存
java·mybatis·postgis·geojson
Full Stack Developme5 天前
MyBatis-Plus(MP)AST 抽象语法树 设计原理
java·tomcat·mybatis
han_hanker6 天前
mybatis-plus service层拥有的方法
mybatis