【Mybatis-plus】Mybatis-plus逆向工程

Mybatis-plus逆向工程

概念

MyBatis-Plus 逆向工程(Reverse Engineering)是 MyBatis-Plus 提供的一个功能,它允许根据数据库表自动生成对应的实体类、Mapper 接口和 XML 等文件,从而省去手动创建这些文件的步骤。逆向工程能够加速开发过程,减少手写代码的工作量。

实现

mybatis-plus版本3.5.4.1。

导入依赖

这里模板引擎使用velocity,除此之外还有freemaker等模板引擎

<dependency>
	<groupId>com.baomidou</groupId>
	<artifactId>mybatis-plus-generator</artifactId>
	<version>3.5.4.1</version>
</dependency>

<dependency>
	<groupId>com.baomidou</groupId>
	<artifactId>mybatis-plus-core</artifactId>
	<version>3.5.4.1</version>
</dependency>

<dependency>
	<groupId>org.apache.velocity</groupId>
    <artifactId>velocity-engine-core</artifactId>
	<version>2.3</version>
</dependency>

配置数据库:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf8
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver

测试代码:

public class CodeGenerator {
    private static final String URL = "jdbc:mysql://localhost:3306/leadnews_user?useSSL=false&useUnicode=true&characterEncoding=utf8";
    public static void main(String[] args) {
        FastAutoGenerator.create(URL, "root", "123456")
                .globalConfig(builder -> builder.outputDir("D:\\1study"))
                .strategyConfig(builder -> builder.addInclude("表名[可以一个也可以多个]"))
                .execute();
    }
}

测试结果:

文件夹里为对应的文件

在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值