工具
Intellij IDEA
修改build.gradle
添加如下内容:
//plugins 的上面只允许 buildscript{} 和 plugins{} 两种
plugins { id "com.arenagod.gradle.MybatisGenerator" version "1.4" //gradle提供的mybatis generator插件 }
dependencies { //https://mvnrepository.com/artifact/com.arenagod.gradle.MybatisGenerator/com.arenagod.gradle.MybatisGenerator.gradle.plugin compile group: 'org.mybatis.generator', name: 'mybatis-generator-core', version:'1.3.2'}
mybatisGenerator { verbose = true configFile = './src/main/resources/mybatis/generator.xml' }generator.xml 内容如下:
<?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> <!-- 数据库驱动包位置 --> <classPathEntry location="F:\iot-repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar" /> <!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />--> <context id="DB2Tables" targetRuntime="MyBatis3"> <!-- optional,旨在创建class时,对注释进行控制 --> <commentGenerator> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="true"/> </commentGenerator> <!-- 数据库链接URL、用户名、密码 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/drgs_bzfx?characterEncoding=utf8" userId="root" password=""> <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa">--> </jdbcConnection> <!--<javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> --> <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="caye.bzfx.module.task" targetProject="./src/main/java"> <!-- 是否允许子包,即targetPackage.schemaName.tableName --> <!--<property name="enableSubPackages" value="false"/>--> <!-- 是否对类CHAR类型的列的数据进行trim操作 --> <property name="trimStrings" value="true"/> <!-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 --> <!--<property name="immutable" value="false"/>--> </javaModelGenerator> <!-- 生成的映射文件包名和位置 --> <sqlMapGenerator targetPackage="mapper" targetProject="./src/main/resources/"> <!--<property name="enableSubPackages" value="false" />--> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="caye.bzfx.module.task" targetProject="./src/main/java"> <!--<property name="enableSubPackages" value="false" /> --> </javaClientGenerator> <!--<table tableName="cmm_app_t" domainObjectName="App" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> --> <!--<table tableName="metric_unit_t" domainObjectName="Unit" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> --> <!--<table tableName="metric_spec_t" domainObjectName="MetricSpec" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />--> <!-- <table tableName="metric_info_t" domainObjectName="Metric" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> --> <!-- <table tableName="alarm_rule_t" domainObjectName="AlarmRule" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> --> <!-- <table tableName="thing_data_code_t" domainObjectName="Code" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />--> <table tableName="drg_task_t" domainObjectName="Task" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> </context> </generatorConfiguration>