码迷,mamicode.com
首页 > 移动开发 > 详细

mybatis 自动生成 mapper

时间:2019-09-28 00:39:04      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:model   sqlmap   title   name   resource   enabled   instance   ESS   date   

生成命令

java -jar generator.jar -configfile generator.xml -overwrite

oracle 的配置

<?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="ojdbc14.jar" />
    <context id="context1">
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@139.219.199.9:1521:coaltest" userId="fw_data_user" password="123456" />
        <javaModelGenerator targetPackage="com" targetProject="src" />
        <sqlMapGenerator targetPackage="com" targetProject="src" />
        <javaClientGenerator type="XMLMAPPER" targetPackage="com" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <table tableName="T_PF_CHECK_RESULT" domainObjectName="PfCheckResult"
            delimitIdentifiers="true" delimitAllColumns="true"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false">
        </table>
    </context>
</generatorConfiguration>

mysql 的配置

<?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="mysql-connector-java-8.0.13.jar" />
    <context id="context1">
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://192.168.2.163:3306/gpftest" userId="root" password="123456" />
        <javaModelGenerator targetPackage="com" targetProject="src" />
        <sqlMapGenerator targetPackage="com" targetProject="src" />
        <javaClientGenerator type="XMLMAPPER" targetPackage="com" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <table tableName="t_user" domainObjectName="User"
            delimitIdentifiers="true" delimitAllColumns="true"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false">
        </table>
    </context>
</generatorConfiguration>

配置更新:

<?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="mysql-connector-java.jar" />
    <context id="context1">
        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://ip:3306/dbname" userId="" password="">
            <property name="useInformationSchema" value="true"/>
        </jdbcConnection>
        <javaModelGenerator targetPackage="com" targetProject="src" />
        <sqlMapGenerator targetPackage="com" targetProject="src" />
        <javaClientGenerator type="XMLMAPPER" targetPackage="com" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <table tableName="base_meta_instance_resource"
            domainObjectName="BaseMetaInstanceResource"
            delimitIdentifiers="true"
            delimitAllColumns="true"
            enableSelectByPrimaryKey="true"
            enableInsert="true"
            enableDeleteByPrimaryKey="true"
            enableUpdateByPrimaryKey="true">
        </table>
    </context>
</generatorConfiguration>

解决问题

生成的 mapper.xml 中有重复代码

解决办法:xml 配置中,去掉下面代码

<property name="suppressAllComments" value="true"/>

无法生成 selectByPrimaryKey、deleteByPrimaryKey 等方法

将 mysql 驱动的版本降低到 5.x,尚未验证

or

添加下面的标签(有效,推荐使用)

<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="" userId="" password="">
    <property name="useInformationSchema" value="true"/>
</jdbcConnection>

参考文章

相关文章

mytatis 自动生成工具

生成器 XML 配置项

mybatis 自动生成 mapper

标签:model   sqlmap   title   name   resource   enabled   instance   ESS   date   

原文地址:https://www.cnblogs.com/xmsx/p/11601148.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!