云自無心水自閑

          天平山上白云泉,云自無心水自閑。何必奔沖山下去,更添波浪向人間!
          posts - 288, comments - 524, trackbacks - 0, articles - 6
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          介紹作為iBatis輔助工具的iBator的使用方法

          Posted on 2009-10-07 20:18 云自無心水自閑 閱讀(3936) 評論(6)  編輯  收藏 所屬分類: Java 、心得體會 、iBatis 、Eclipse

          目前從實際應(yīng)用來看,ORM的老大自然是Hibernate,可是iBatis因為相對比較直觀、學(xué)習(xí)曲線相對較低,因而也贏得了不少用戶的青睞。
          本文主要介紹作為iBatis輔助工具的iBator的使用方法。
          iBator是一個iBatis相關(guān)代碼的自動生成工具。
          1、安裝iBator的插件
          在Eclipse中,使用添加站點的方法,輸入網(wǎng)址http://ibatis.apache.org/tools/ibator,進行iBator的安裝。
          2、建議不要直接在使用iBatis的項目里直接使用iBator,推薦另外單獨建立一個項目來生成。比如,建立一個項目叫:IbatorPrj
          3、右鍵點擊IbatorPrj這個項目,如果剛才的插件安裝正確的話,就會看到一個“Add iBATOR to the build path”的選項,點擊一下。
          4、創(chuàng)建iBator的配置文件。下面是我的例子,大家在實際使用的過程中,需要根據(jù)自己的情況進行相應(yīng)的修改。
          主要就是數(shù)據(jù)庫JDBC庫的路徑、數(shù)據(jù)庫驅(qū)動的類名、項目的名稱、包名等。
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE ibatorConfiguration
            PUBLIC "-//Apache Software Foundation//DTD Apache iBATIS Ibator Configuration 1.0//EN"
            "http://ibatis.apache.org/dtd/ibator-config_1_0.dtd">

          <ibatorConfiguration>
                  <classPathEntry location="c:\javaLibs\MySql\mysql-connector-java-5.0.6-bin.jar" />

                  <ibatorContext id="SampleiBator" targetRuntime="Ibatis2Java5">
                          <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                                  connectionURL="jdbc:mysql://localhost/sample" userId="root" password="admin">
                          </jdbcConnection>

                          <javaTypeResolver>
                                  <property name="forceBigDecimals" value="false" />
                          </javaTypeResolver>

                          <javaModelGenerator targetPackage="com.sample"
                                  targetProject="IbatorPrj\src">
                                  <property name="enableSubPackages" value="true" />
                                  <property name="trimStrings" value="true" />
                          </javaModelGenerator>

                          <sqlMapGenerator targetPackage="com.sample.xml"
                                  targetProject="IbatorPrj\src">
                                  <property name="enableSubPackages" value="true" />
                          </sqlMapGenerator>

                          <daoGenerator type="GENERIC-CI" targetPackage="com.sample.dao"
                                  targetProject="IbatorPrj\src">
                                  <property name="enableSubPackages" value="true" />
                          </daoGenerator>

                          <table schema="sample" tableName="tab1" domainObjectName="JavaBean1">
                                  <property name="useActualColumnNames" value="false" />
                                  <generatedKey column="ID" sqlStatement="MySql" identity="true" />
                          </table>

                  </ibatorContext>
          </ibatorConfiguration>
          5、配置文件生成完畢后,右鍵點擊這個文件,選擇“Generate iBatis Artifact”,然后你就在配置的文件夾下找到自動生成的文件了。




          評論

          # re: 介紹作為iBatis輔助工具的iBator的使用方法  回復(fù)  更多評論   

          2009-10-08 10:37 by Scorpio Zhen
          主要生產(chǎn)nameingSQl還是什么?

          # re: 介紹作為iBatis輔助工具的iBator的使用方法  回復(fù)  更多評論   

          2009-10-08 13:05 by weager
          學(xué)習(xí)下

          # re: 介紹作為iBatis輔助工具的iBator的使用方法  回復(fù)  更多評論   

          2009-10-08 13:25 by usherlight
          還可以生成數(shù)據(jù)表對應(yīng)的javabean和操作數(shù)據(jù)表的dao文件

          # re: 介紹作為iBatis輔助工具的iBator的使用方法  回復(fù)  更多評論   

          2009-10-08 17:17 by 和風(fēng)賽跑
          這個東西可定制性太差,自己用模板工具寫個代碼生成工具要比這個靈魂的多!

          # re: 介紹作為iBatis輔助工具的iBator的使用方法  回復(fù)  更多評論   

          2009-12-17 21:48 by 團派家園
          ibaits3.0出來了,但文檔很少。

          # re: 介紹作為iBatis輔助工具的iBator的使用方法  回復(fù)  更多評論   

          2010-02-04 08:40 by 云自無心水自閑
          文檔一直是許多開源項目的薄弱環(huán)節(jié)。
          主站蜘蛛池模板: 杨浦区| 冷水江市| 卢湾区| 荥经县| 长武县| 台南县| 汶上县| 牟定县| 永年县| 玉山县| 定安县| 仲巴县| 静宁县| 咸阳市| 福泉市| 当雄县| 安顺市| 贵溪市| 温州市| 巴林左旗| 肇源县| 繁昌县| 阿拉尔市| 合阳县| 蕉岭县| 友谊县| 柏乡县| 云霄县| 黔西| 定陶县| 清原| 佳木斯市| 桃源县| 栾城县| 磴口县| 沁阳市| 宜君县| 凤冈县| 南川市| 曲周县| 湾仔区|