mybatis的generator使用,逆向工程生成mapper接口的使用方法,如selectOne。

官方手冊: mybatis-generator

學習方法:

  1. 按照官網手冊生成mapper接口和pojo 官方教程
  2. 理解配置bgm.xml
  3. 注意版本問題(1.4版本捨棄了example,藉助 MyBatis Dynamic SQL庫)。
  4. 重點知道生成的mapper接口的用法官方教程
  5. 所有的東西,官方手冊上都有,我只是搬運工而已。

配置文件:

<?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>
    <!--重點是targetRuntime的屬性選值-->
    <context id="db2Table" defaultModelType="flat" targetRuntime="MyBatis3Simple">
        <!--註釋生成器-->
        <commentGenerator>
            <!--關閉所有的註釋-->
            <property name="suppressAllComments" value="true"/>
            <!--關閉註釋時間戳-->
            <property name="suppressDate" value="true"/>
        </commentGenerator>
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/hchat"
                        userId="root"
                        password="zhan">
        </jdbcConnection>
        <javaModelGenerator targetPackage="noodzhan.pojo" targetProject=".\src\main\java" >
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!--sqlMapGenerator 是生成mapper的xml文件的,只有當javaClientGenerator的type選擇爲xmlmapper時才生效-->
        <sqlMapGenerator targetPackage="example.mapper" targetProject="src/main/resources"/>
        <!--生成mapper接口-->
        <javaClientGenerator targetPackage="noodzhan.mapper" targetProject=".\src\main\java" type="XMLMAPPER"></javaClientGenerator>
        <table tableName="tb_user" domainObjectName="User"></table>
        <table tableName="tb_friend" domainObjectName="Friend"></table>
        <table tableName="tb_chat_record" domainObjectName="ChatRecord"></table>
        <table tableName="tb_friend_req" domainObjectName="FriendReq"></table>
    </context>
</generatorConfiguration>
````
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章