JAVA—咖啡館

          ——歡迎訪問rogerfan的博客,常來《JAVA——咖啡館》坐坐,喝杯濃香的咖啡,彼此探討一下JAVA技術,交流工作經驗,分享JAVA帶來的快樂!本網站部分轉載文章,如果有版權問題請與我聯系。

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            447 Posts :: 145 Stories :: 368 Comments :: 0 Trackbacks

          目前從實際應用來看,ORM的老大自然是Hibernate,可是iBatis因為相對比較直觀、學習曲線相對較低,因而也贏得了不少用戶的青睞。
          本文主要介紹作為iBatis輔助工具的iBator的使用方法。
          iBator是一個iBatis相關代碼的自動生成工具。
          1、安裝iBator的插件
          在Eclipse中,使用添加站點的方法,輸入網址http://ibatis.apache.org/tools/ibator,進行iBator的安裝。
          2、建議不要直接在使用iBatis的項目里直接使用iBator,推薦另外單獨建立一個項目來生成。比如,建立一個項目叫:IbatorPrj
          3、右鍵點擊IbatorPrj這個項目,如果剛才的插件安裝正確的話,就會看到一個“Add iBATOR to the build path”的選項,點擊一下。
          4、創建iBator的配置文件。下面是我的例子,大家在實際使用的過程中,需要根據自己的情況進行相應的修改。
          主要就是數據庫JDBC庫的路徑、數據庫驅動的類名、項目的名稱、包名等。
          <?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”,然后你就在配置的文件夾下找到自動生成的文件了。

          posted on 2009-11-24 10:26 rogerfan 閱讀(2135) 評論(0)  編輯  收藏 所屬分類: 【開源技術】
          主站蜘蛛池模板: 洛隆县| 六枝特区| 高淳县| 德保县| 宁德市| 安丘市| 台江县| 望谟县| 灵石县| 武冈市| 德格县| 贵德县| 襄垣县| 上高县| 武穴市| 西峡县| 通江县| 牟定县| 甘肃省| 临沧市| 怀集县| 沈丘县| 仙游县| 高雄市| 裕民县| 津市市| 正镶白旗| 肥乡县| 柳江县| 黎城县| 连州市| 绥滨县| 南宁市| 内丘县| 慈利县| 眉山市| 牡丹江市| 南澳县| 泸定县| 凤翔县| 施秉县|