今天看了mybatis-Generator的官方文檔,研究了一下,決定本身也搭一個,可是官方文檔和大部分資料都是基於maven項目的,查了gradle的官方文檔,終於找到了官方配置,很激動(^-^)V,記錄下來,方便記憶也同時分享給你們~
mybatis-Generator官方文檔:http://www.mybatis.org/genera...
Gradle官方文檔:https://plugins.gradle.org/pl...html
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' }
按照剛纔的配置路徑,在 resources 文件夾下創建 generator.xmljava
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <context id="my" targetRuntime="MyBatis3"> <!--自動實現Serializable接口--> <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> <!-- 去除自動生成的註釋 --> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!--數據庫基本信息--> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/takin_write" userId="murasakiseifu" password="123456"> </jdbcConnection> <!--生成實體類的位置以及包的名字--> <!--一樣Mac用戶:targetProject 爲全路徑--> <javaModelGenerator targetPackage="com.example.entity" targetProject="/Users/murasakiseifu/mybatisGenerator/src/main/java"> <!-- enableSubPackages:是否讓schema做爲包的後綴 --> <property name="enableSubPackages" value="true" /> <!-- 從數據庫返回的值被清理先後的空格 --> <property name="trimStrings" value="true" /> </javaModelGenerator> <!--生成映射文件存放位置--> <!--一樣Mac用戶:targetProject 爲全路徑--> <sqlMapGenerator targetPackage="mapper" targetProject="/Users/murasakiseifu/mybatisGenerator/src/main/resources"> <!-- enableSubPackages:是否讓schema做爲包的後綴 --> <property name="enableSubPackages" value="false"/> </sqlMapGenerator> <!--生成Dao類存放位置,mapper接口生成的位置--> <!--一樣Mac用戶:targetProject 爲全路徑--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.example.dao" targetProject="/Users/murasakiseifu/mybatisGenerator/src/main/java"> <!-- enableSubPackages:是否讓schema做爲包的後綴 --> <property name="enableSubPackages" value="false"/> </javaClientGenerator> <!-- 配置表信息 --> <!-- schema即爲數據庫名 tableName爲對應的數據庫表 domainObjectName是要生成的實體類 enable*ByExample 是否生成 example類 --> <table schema="takin_write" tableName="c_student" domainObjectName="Student" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"> </table> </context> </generatorConfiguration>
雙擊 mbGeneratormysql
出現以下提示爲成功git
http://blog.csdn.net/u0110947...
http://blog.csdn.net/shaohx05...
https://github.com/kingcos/My...github