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();
    }
}
相关推荐
SuperArc19998 小时前
SpringBoot+Slf4j+Log4j2+mybatis 日志整合
spring boot·mybatis·log4j2·slf4j·日志整合
可乐ea10 小时前
【Spring Boot + MyBatis|第4篇】MyBatis 动态 SQL:if、where、foreach 使用详解
java·spring boot·后端·sql·mybatis
一条泥憨鱼14 小时前
苍穹外卖【day5|Redis与店铺营业状态设置】
java·后端·mybatis·苍穹外卖
来杯@Java1 天前
学生选课管理系统(基于springboot+vue前后端分离的项目)计算机毕业设计java
java·spring boot·spring·vue·毕业设计·maven·mybatis
我是唐青枫1 天前
Java MyBatis 实战指南:XML 映射、动态 SQL 与数据访问层设计
java·mybatis
碎碎念_4922 天前
SpringBoot和MyBatis框架·速通版
spring boot·后端·mybatis
唐青枫3 天前
Java MyBatis 实战指南:XML 映射、动态 SQL 与数据访问层设计
java·mybatis
一条泥憨鱼3 天前
苍穹外卖【day3|菜品管理】
java·数据库·sql·mysql·mybatis
INFINI Labs3 天前
Elasticsearch 6/7/8 到 Easysearch 2.x 迁移指南
大数据·elasticsearch·mybatis·向量·snapshot
CodeStats3 天前
从JDBC时代到MyBatis封神:SQL全流程手写ORM实战
sql·mysql·mybatis