版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_22797429/article/details/84196874
文章目录
前言
mybatis-generator工具是用来生成mybatis的model,mapper,dao持久层代码。本文结合现在主流的构建工具是gradle,连接数据库自动生成相应代码。虽然mybatis-generator没有提供gradle的插件,但是可以用gradle调用ant任务,因此,gradle也能间接启动mybatis-generator。
环境
- JDK 1.8
- IntelliJ IDEA 2017.2.2
- Gradle 3.5.0
- mysql
配置
以shopmall-order订单服务为例,通过配置shopmall-order.gradle和generator.xml两个文件,来自动生成相应entity、mapper、xml等。
shopmall-order.gradle
description = '''shopmall-order'''
dependencies {
compile project(":shopmall-order-api")
compile project(':shopmall-account-api')
}
//mybatis-generator.xml 配置路径
// mac下是找不到 ./src 路径的,需要全路径,如下配置。windows则为src/main/resources/generator.xml
mybatisGenerator {
verbose = true
configFile = 'src/main/resources/generator.xml'
}