今天看了mybatis-Generator的官方文档,研究了一下,决定自己也搭一个,但是官方文档和大部分资料都是基于maven项目的,查了gradle的官方文档,终于找到了官方配置,很激动(^-^)V,记录下来,方便记忆也同时分享给大家~

mybatis-Generator官方文档:http://www.mybatis.org/genera...

Gradle官方文档:https://plugins.gradle.org/pl...

gradle

buildscript {

ext {

springBootVersion = '1.5.10.RELEASE'

}

repositories {

mavenCentral()

//添加maven仓库

maven {

url "https://plugins.gradle.org/m2/"

}

}

dependencies {

classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")

// mybatis-generator 插件路径

classpath "gradle.plugin.com.arenagod.gradle:mybatis-generator-plugin:1.4"

}

}

apply plugin: 'java'

apply plugin: 'eclipse'

apply plugin: 'org.springframework.boot'

//引入 mybatis-generator 插件

apply plugin: "com.arenagod.gradle.MybatisGenerator"

group = 'com.example'

version = '0.0.1-SNAPSHOT'

sourceCompatibility = 1.8

repositories {

mavenCentral()

}

dependencies {

compile('org.springframework.boot:spring-boot-starter-web')

testCompile('org.springframework.boot:spring-boot-starter-test')

//数据源

compile 'com.alibaba:druid-spring-boot-starter:1.1.2'

compile 'mysql:mysql-connector-java:6.0.6'

//配置mybatis

compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"

//mybatis-generator core 包

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

}

configurations {

mybatisGenerator

}

// mybatis-generator.xml 配置路径

//这里会遇到个问题:MyBatis Generator 通过xml生成,有日志但是没有生成文件成功的问题,

//原因:mac下是找不到 ./src 路径的,需要全路径,如下配置。windows则为src/main/resources/generator.xml

mybatisGenerator {

verbose = true

configFile = '/Users/murasakiseifu/mybatisGenerator/src/main/resources/generator.xml'

}

generator.xml

按照刚才的配置路径,在 resources 文件夹下建立 generator.xml

/p>

PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"

"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

connectionURL="jdbc:mysql://127.0.0.1:3306/takin_write"

userId="murasakiseifu"

password="123456">

domainObjectName="Student" enableCountByExample="false"

enableDeleteByExample="false" enableSelectByExample="false"

enableUpdateByExample="false">

生成代码

双击 mbGenerator

bV4WYq?w=1476&h=1124

出现如下提示为成功

bV4WYK?w=3358&h=734

包结构

bV4WYT?w=1004&h=1294

参考

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐