赞
踩
<!--自动生成代码脚本-->
<?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="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<property name="javaFileEncoding" value="UTF-8"/>
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
<!-- caseSensitive默认false,当数据库表名区分大小写时,可以将该属性设置为true -->
<property name="caseSensitive" value="true"/>
</plugin>
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--jdbc参数-->
<jdbcConnection driverClass="${driverClass}"
connectionURL="${connectionURL}"
userId="${userId}"
password="${password}">
</jdbcConnection>
<!--dao生成路径-->
<javaModelGenerator targetPackage="${modelPackage}"
targetProject="${src_main_java}"/>
<!--mybatisxml生成路径-->
<sqlMapGenerator targetPackage="${sqlMapperPackage}"
targetProject="${src_main_resources}"/>
<!--pojo生成路径-->
<javaClientGenerator targetPackage="${mapperPackage}"
targetProject="${src_main_java}"
type="XMLMAPPER"/>
<table tableName="TB_LOG_OPERATE"
domainObjectName="OperateLogs"
enableCountByExample="false"
enableUpdateByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false">
<generatedKey column="id" sqlStatement="Mysql" identity="true"/>
</table>
</context>
</generatorConfiguration>
env=dev
# 需要生成的model存放路径
modelPackage=com.asiainfo.etrip.modules.ecar.bean
# 生成的mapper接口类所在包
mapperPackage=com.asiainfo.etrip.modules.ecar.dao
# 生成的mapper xml文件所在包,默认存储在resources目录下
sqlMapperPackage=mybatis_mapper
// 依赖
dependencies {
mybatisGenerator 'org.mybatis.generator:mybatis-generator-core:1.3.2'
mybatisGenerator 'mysql:mysql-connector-java:5.1.36'
mybatisGenerator 'tk.mybatis:mapper:3.3.2'
}
// jdbc参数
def getDbProperties = {
def properties = new Properties()
file("src/main/resources/jdbc-mysql.properties").withInputStream { inputStream ->
properties.load(inputStream)
}
properties;
}
// 具体任务配置
task mybatisGenerate << {
def properties = getDbProperties()
ant.properties['targetProject'] = projectDir.path
ant.properties['driverClass'] = properties.getProperty("jdbc.driverClassName")
ant.properties['connectionURL'] = properties.getProperty("jdbc.url")
ant.properties['userId'] = properties.getProperty("jdbc.user")
ant.properties['password'] = properties.getProperty("jdbc.password")
ant.properties['src_main_java'] = sourceSets.main.java.srcDirs[0].path
ant.properties['src_main_resources'] = sourceSets.main.resources.srcDirs[0].path
ant.properties['modelPackage'] = this.modelPackage
ant.properties['mapperPackage'] = this.mapperPackage
ant.properties['sqlMapperPackage'] = this.sqlMapperPackage
ant.taskdef(
name: 'mbgenerator',
classname: 'org.mybatis.generator.ant.GeneratorAntTask',
classpath: configurations.mybatisGenerator.asPath
)
ant.mbgenerator(overwrite: true,
configfile: 'mybatis/generatorConfig.xml', verbose: true) {
propertyset {
propertyref(name: 'targetProject')
propertyref(name: 'userId')
propertyref(name: 'driverClass')
propertyref(name: 'connectionURL')
propertyref(name: 'password')
propertyref(name: 'src_main_java')
propertyref(name: 'src_main_resources')
propertyref(name: 'modelPackage')
propertyref(name: 'mapperPackage')
propertyref(name: 'sqlMapperPackage')
}
}
}
graph LR
在build.gradle文件中右击-->选中run上面配置的任务
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。