Abator —— IBatis 代碼產生工具

來源:互聯網
上載者:User

文章出自:http://writeblog.csdn.net/PostEdit.aspx

對於IBatis應用最煩人的重複工作就是不停的寫DAO,DTO,和xml檔案裡面的sqlmap,其實很多時候這些工作是重複而且無聊的。好在我們還有abator (http://ibatis.apache.org/abator.html ),一個IBatis自動產生工具,他可以協助你產生大量的DAO,DTO和sqlmap。
如果你使用eclipse作為IDE那麼事情就很簡單了(相信沒有幾個人不在用):
安裝Eclipse外掛程式
1. 要求eclipse3.1,jdk1.4以上
2. 在eclipse上安裝abator外掛程式
    eclipse功能表列 --> help --> Software Updates --> Find And Install...
    在彈出的對話方塊中選擇 “Search for new features to install” 然後點擊 “next”
    在對話方塊中點擊按鈕 New Remort Site...  在彈出的對話方塊中的URL輸入框中填寫 http://ibatis.apache.org/tools/abator ,Name輸入框就隨便寫些什麼了。
    點擊Finish,安裝外掛程式,然後重新啟動eclipse

下面測試一下功能
1. 建立一個java工程
2. 在eclipse功能表列中興建一個 abator 設定檔
    File -->  Abator  for  iBatis Configration File

好的,我們完成了建立設定檔,下面打abator設定檔,看看裡面怎麼去配置
開啟後內容基本上是這樣 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="???"           connectionURL="???"           userId="???"           password="???">         <classPathEntry location="???" />       </jdbcConnection>          <javaModelGenerator targetPackage="???" targetProject="???" />       <sqlMapGenerator targetPackage="???" targetProject="???" />       <daoGenerator type="IBATIS" targetPackage="???" targetProject="???" />          <table schema="???" tableName="???">         <columnOverride column="???" property="???" />       </table>        </abatorContext>   </abatorConfiguration>  

你需要做的是替換一些???:
1. 填寫driverClass(jdbc驅動,例如oracle的就是oracle.jdbc.driver.OracleDriver)
2. 填寫connectionURL(連接字串,例如oracle的就是jdbc:oracle:thin:@192.168.0.246:1521:test)
3. 填寫classPathEntry的location(jdbc驅動jar包的位置,例如E:/project/ibatistest/WebContent/WEB-INF/lib/ojdbc14.jar)
4. 填寫javaModelGenerator,產生的DTO(java model 類)
    targetPackage:目標包的位置,如 com.test.dto
    targetProject:目標工程名稱,填寫設定檔所在的eclipse工程名
5. 填寫sqlMapGenerator ,產生的xml sqlmap的相關配置
    targetPackage:目標位置,如 com.test.sqlmap
    targetProject:目標工程名稱,填寫設定檔所在的eclipse工程名
6. 填寫daoGenerator ,產生的DAO的相關配置
    type:產生的dao實現的類型,如果你使用spring的話寫SPRING,否則寫IBATIS
    targetPackage:目標位置,如 com.test.dao
    targetProject:目標工程名稱,填寫設定檔所在的eclipse工程名
7. 配置相關資料庫的表
    schema:資料庫schema,oracle就是填寫資料庫的使用者名稱
    tableName:表名 xml 代碼 <columnOverride column="???" property="???" />  


     可以先不用配置,刪除就可以了

下面開始產生:
在設定檔上點解右鍵,選擇 “Generate iBatis Artifacts”
OK,看看產生了什麼吧。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.