[Internship@True]วันที่ 24

เมื่อก่อนที่ได้ Code พี่มาศึกษา เราต้องไล่แกะ Code และมาเขียนเองหมดเลย แต่ตอนนี้พี่เค้าแนะนำ Tool ตัวหนึ่งมาใช้ ชื่อว่า aBator ที่จะช่วยให้ใช้งาน ibatis ได้สะดวกขึ้น โดยจะมีการ Gen Class ต่างๆ, DAO และ sqlMap มาใช้เลยรวมถึง sql พื้นฐานต่างๆด้วย ทำให้เราสบายขึ้นเยอะ

การใช้ aBator ในการ gen ไฟล์ที่เกี่ยวข้องในการใช้ ibatis กับ Spring

    1. ไฟล์ download ไฟล์มา โดยมีแหล่งความรู้ ดังนี้
      • http://java.ociweb.com/mark/programming/Abator.html
      • http://amolchaudhari.wordpress.com/2007/08/31/configure-abator-on-eclipse/
      • http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch14s05.html
    2. import เข้ามาในโปรเจค
    3. ไฟล์ที่เราจะต้องรู้
      • /config/ibatorConfig.xml ซึ่งก็จะมีส่วนที่จะต้องมาแก้ไขครั้งนี้
    4. ต้องมาแก้ Path ของไฟล์ ibator-config_1_0.dtd ให้ถูกต้อง
      [xml]<!DOCTYPE ibatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN" "D:\MD_WORK\eclipse\workspace\aBator-3.0\config\ibator-config_1_0.dtd">[/xml]
    5. กำหนด Class Path เพื่อให้รู้จักกับ Oracle (ไฟล์ classes12.jar)
      [xml]<classPathEntry location="D:\MDR\defaultroot\WEB-INF\lib\classes12.jar">[/xml]

  1. แก้ไขในส่วนของ connection ให้ตรงกับความเป็นจริง
    [xml]<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
    connectionURL="jdbc:oracle:oci8:@TEST.ABC.CO.TH"
    userId="xxxxx"
    password="xxxxxxx">
    </jdbcConnection>[/xml]
  2. กำหนดข้อมูลในส่วนของ javaModelGenerator
    [xml]<javaModelGenerator targetPackage="com.rmv.mdr.dataaccess.bean" targetProject="OUTPUT/src"><property name="enableSubPackages" value="false" /><property name="trimStrings" value="true" /></javaModelGenerator>[/xml]
  3. กำหนดข้อมูลในส่วนของ sqlMapGenerator
    [xml]<sqlMapGenerator targetPackage="com.rmv.mdr.dataaccess.service.sqlmap" targetProject="OUTPUT/src">
    <property name="enableSubPackages" value="false" />
    </sqlMapGenerator>[/xml]
  4. กำหนดข้อมูลในส่วนของ daoGenerator
    [xml]<daoGenerator type="SPRING" targetPackage="com.rmv.mdr.dataaccess.service" targetProject="OUTPUT/src">
    <property name="enableSubPackages" value="false" />
    </daoGenerator>[/xml]
  5. กำหนดข้อมูลในส่วนของ Table และการตั้งค่าต่างๆ
    [xml]<table tableName="MD_INBOUNDAUDIT_REGEXTV01"
    enableCountByExample="false"
    selectByExampleQueryId="false"
    enableInsert="true"
    enableInsertSelective="false"
    enableSelectByExample="false"
    enableSelectByPrimaryKey="true"
    enableSelectBySelective="true"
    enableDeleteByExample="false"
    enableDeleteByPrimaryKey="true"
    enableDeleteBySelective="true"
    enableUpdateByExample="false"
    enableUpdateByPrimaryKey="true"
    enableUpdateByPrimaryKeySelective="true"
    >
    <property name="useActualColumnNames" value="false"/>;
    </table>[/xml]
  6. ไปที่ src/com/ibator/runner เปิดไฟล์ Testgenerate.java และลองรันดูผลลัพธ์ ซึ่งจะอยู่ที่โพลเดอร์ OUTPUT/src

Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts to your email.