Skip to content
mybatis-plus code generator for gradle plugin
Groovy Java Shell
Branch: master
Clone or download
leonxia
leonxia ci
Latest commit 9a06993 Jan 2, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
basic plugin Dec 21, 2018
buildSrc ci Jan 2, 2019
doc update Dec 21, 2018
gradle/wrapper update Dec 21, 2018
spring-demo ci Jan 2, 2019
sql update Dec 21, 2018
.gitignore update Dec 21, 2018
.travis.yml ci Jan 2, 2019
PluginBuild.sh plugin Dec 21, 2018
PluginClean.sh plugin Dec 21, 2018
PluginUpload.sh update Dec 21, 2018
README.md ci Jan 2, 2019
build.gradle ci Jan 2, 2019
gradlew init Dec 20, 2018
gradlew.bat init Dec 20, 2018
settings.gradle update Dec 21, 2018

README.md

Mybatis Plus Gradle Generator


介绍

Web开发中使用mybatis比较多,MyBatis Plus是一个比较好的扩展,并且还可以自动生成代码,比较方便。 但是MyBatis Plus 对maven比较友好,对Gradle就比较差了,现在Spring Boot也对Gradle支持比较好,在使用Gradle生成代码的时候就比较麻烦。

Build Status

使用姿势

本插件需要结合Spring Boot项目一起使用,如下所示,首先添加插件依赖,当前版本为 Download

buildscript {
    ext {
        springBootVersion = '2.1.1.RELEASE'
    }
    repositories {
        maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
        maven { url "https://dl.bintray.com/liushuixiaoxia/maven"  }
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("cn.mycommons:mpg:${mpgVesion}")
    }
}

然后配置相关属性即可,本配置可以参考MyBatis Plus 代码生成官方文档,基本配置和官方配置一样。

示例:表名为tb_app_info,前缀为tb_,生成的entity为AppInfo,mapper为AppInfoMapper.xml

apply plugin: 'mpg'
mpg {
    enable = true

    globalConfig {
        outputDir = projectDir.path + "/src/main/java"
        author = "Admin"
        open = false
        baseResultMap = true
    }

    dataSourceConfig {
        driverName = "com.mysql.jdbc.Driver"
        url = "jdbc:mysql://localhost:3306/mpg_test?useUnicode=true&characterEncoding=utf8&useSSL=false"
        username = "root"
        password = "admin"
    }

    packageConfig {
        parent = "cn.mycommons.springdemo.mpg"
        entity = "mybatis.entity"
        mapper = "mybatis.mapper"
    }

    xmlMapperConfig {
        path = projectDir.path + "/src/main/resources/mapper/"
        name = "AppInfoMapper.xml"
    }

    strategyConfig {
        include = ["tb_app_info"]
        tablePrefix = ["tb_"]
        entityLombokModel = true
        restControllerStyle = true
        superEntityClass = "cn.mycommons.basic.dto.BaseEntity"
        logicDeleteFieldName = "is_delete"
        superEntityColumns = ["create_by", "create_time", "update_by", "update_time", "remark", "is_delete"]
        entityTableFieldAnnotationEnable(true)
        controllerMappingHyphenStyle = true
        superControllerClass = "cn.mycommons.basic.controller.BaseController"
    }
}

下面为自定义配置,表示生成xmlMapper的文件路径。

xmlMapperConfig {
    path = projectDir.path + "/src/main/resources/mapper/"
    name = "AppInfoMapper.xml"
}

然后执行Gradle Task mpg 即可。

mpg

相关链接

MyBatis Plus

MyBatis Plus 文档

MyBatis Plus Gradle Plugin

You can’t perform that action at this time.