当前位置:   article > 正文

Mybatis自动生成代码_ant.mbgenerator路径

ant.mbgenerator路径

Mybatis自动生成代码(dao,mapper,pojo)

 <!--自动生成代码脚本-->
 <?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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

配置文件

env=dev
# 需要生成的model存放路径
modelPackage=com.asiainfo.etrip.modules.ecar.bean
# 生成的mapper接口类所在包
mapperPackage=com.asiainfo.etrip.modules.ecar.dao
# 生成的mapper xml文件所在包,默认存储在resources目录下
sqlMapperPackage=mybatis_mapper
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

build.gradle 任务配置

// 依赖
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')
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

执行方式

graph LR
在build.gradle文件中右击-->选中run上面配置的任务
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/307493
推荐阅读
相关标签
  

闽ICP备14008679号