ibatis – 自動代碼產生工具abator 使用介紹

來源:互聯網
上載者:User
本文輕鬆的讓你根據資料庫表產生通過ibatis訪問資料庫的相關代碼
一、獲得
      http://ibatis.apache.org/abator.html
二、下載以後解包到目錄
      D:/abator-0.6.5-124
          /abator.jar
          /abator-src.zip
三、設定檔
      建立一個設定檔config.xml,內容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE abatorConfiguration PUBLIC
  "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN"
  "http://ibatis.apache.org/dtd/abator-config_1_0.dtd">
<abatorConfiguration>
  <abatorContext>
    <!-- TODO: Add Database Connection Information -->
    <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
        connectionURL="jdbc:oracle:thin:@172.17.1.103:1521:ora18"
        userId="test"
        password="test">
      <classPathEntry location="D:/Setup/JavaLib/classes12.jar" />
    </jdbcConnection>

    <javaTypeResolver >
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>
 
    <javaModelGenerator targetPackage="test"
        targetProject="/test">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>
 
    <sqlMapGenerator targetPackage="test"
        targetProject="/test">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>
 
    <daoGenerator type="IBATIS" targetPackage="test"
        targetProject="/test">
      <property name="enableSubPackages" value="true" />
    </daoGenerator>

    <table tableName="T_AREA_CODE">
      <columnOverride column="AREA_CODE" property="AREA_CODE" ></columnOverride>
    </table>
  </abatorContext>
</abatorConfiguration>

這裡是Oracle相關的配置,其他資料庫可以以此類推,其中的javaModelGenerator ,sqlMapGenerator ,daoGenerator是將會產生的相關代碼, 可以根據你自己的需要添加或刪除,更完整的設定檔可以看DTD的定義 http://ibatis.apache.org/dtd/abator-config_1_0.dtd

四、運行(在D盤根目錄下建立目錄test,需要存放產生的檔案)
   java -jar abator.jar config.xml false
   java -jar abator.jar config.xml true
   java -cp abator.jar org.apache.ibatis.abator.api.AbatorRunner config.xml false
   java -cp abator.jar org.apache.ibatis.abator.api.AbatorRunner config.xml true
上面四種方式都可以運行,true/false表示是否覆蓋原來的代碼

五、查看產生的檔案,修改。
運行成功後會有如下資訊:
Abator finshed successfully, there were warninigs
至此,你可以手動修改產生的程式碼了。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.