网上都是基于maven生成mapper的教程,gradle的很少都没是成功。最后到官网搜索mapper生成插件,惊喜发现有很多,第一个才更新就试试吧。

官网插件截图

根据插件说明文档配置gradle.build
import tk.mybatis.mapper.generator.MapperPlugin

buildscript {
    ext {
        springBootVersion = '2.0.2.RELEASE'
    }
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath "gradle.plugin.com.cuisongliu.plugin:mybatis-generator:0.9.6"
    }

    configurations {
        all*.exclude group: "commons-logging", module: "commons-logging"
        all*.exclude group: "org.apache.tomcat", module: "tomcat-jdbc"
        all*.exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
    }
}



apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "com.cuisongliu.plugin.mybatis-generator"
version = '1.0-SNAPSHOT'

repositories {
    maven {
        url "https://repo.chejianer.com/repository/maven-public/"
    }

}

mbg {
    overwrite = false
    consoleable = true
    jdbc {
        driver = "com.mysql.jdbc.Driver"
        url = "jdbc:mysql://********?useUnicode=true&characterEncoding=UTF-8&useSSL=false"
        username = "*****"
        password = "*****"
    }
    xml {
        resourcesProject = "src/main/java"
        mapperPlugin = MapperPlugin.class
        mapperMapper = "cn.jgayb.wechat.dao.base.MyMapper"
        mapperPackage = "cn.jgayb.wechat.dao.mapper"
        modelPackage = "cn.jgayb.wechat.domain.entity"
        xmlPackage = "cn.jgayb.wechat.dao.mapper"
        tableName = "wechat_event_original"
        objectName = "WechatEventOriginal"
        mapperSuffix = "Mapper"
    }
}
增加mybatis和通用mapper依赖
dependencies {

    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-aop')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile("org.springframework.boot:spring-boot-starter-log4j2")
    compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2')
//    log4j yml文件解析
    compile('com.fasterxml.jackson.core:jackson-databind')
    compile('com.fasterxml.jackson.dataformat:jackson-dataformat-yaml')

    compile ('org.springframework.boot:spring-boot-starter-jdbc:2.0.0.RELEASE')

    compile 'io.springfox:springfox-swagger2:2.8.0'
    compile 'io.springfox:springfox-swagger-ui:2.8.0'
    compile('com.jfinal:jfinal-weixin:1.9')
    runtime('mysql:mysql-connector-java')
    compileOnly('org.projectlombok:lombok')

//    compile group: 'org.mybatis.generator', name: 'mybatis-generator-core', version: '1.3.6'

//    通用mapper和分页插件
    compile 'tk.mybatis:mapper-spring-boot-starter:2.0.0'

    testCompile('org.springframework.boot:spring-boot-starter-test')
}
idea gradle刷新完毕后 Tasks下面多出来了 mbg, 双击运行一下 顺利生成。

1 对 “Spring boot 2.0 gradle构建 配置通用mapper插件生成mapper和实体”的想法;

发表评论

电子邮件地址不会被公开。 必填项已用*标注