关闭

Ibatis之Eclipse开发插件——Ibator的安装及ibatorConfig.xml的配置

标签: eclipseibatisbuttonwizarddatabasepostgresql
2004人阅读 评论(1) 收藏 举报

Ibatis之Eclipse开发插件——Ibator

1、插件简介

Ibator is a code generator for iBATIS. Ibator will introspect a database table (or many tables) and will generate iBATIS artifacts that can be used to access the table(s). This abates some of the initial nuisance of setting up objects and configuration files to interact with database tables. Ibator seeks to make a major impact on the large percentage of database operations that are simple CRUD (Create, Retrieve, Update, Delete). You will still need to hand code SQL and objects for custom queries, or stored procedures.

Ibator产生的文件有:
  • SqlMap XML Files
  • Java Classes to match the primary key and fields of the table(s)
  • DAO Classes that use the above objects (optional)
Ibator can run as a standalone JAR file, or as an Ant task, or as an Eclipse plugin.

2、插件安装

        我们可以借助Eclipse来安装,当然也可以直接到http://ibatis.apache.org/ibator.html下载,然后解压,将相应的的文件拷贝到eclipse目录。

        2.1、Eclipse自动安装

If you've already installed a prior version of Ibator, simply run the Eclipse Update tool and the new version will be found automatically.
If you've not previously installed Ibator, use the built in Eclipse install support by following these steps:
  • Take the "Help>Software Updates..." Menu Option
  • Select the "Available Software" Tab
  • Press the "Add Site" button
  • Enter the following information:
    Location:
    http://ibatis.apache.org/tools/ibator
  • Press OK
  • Check the box next to "Apache iBATIS Ibator Feature"
  • Press the "Install" button
  • Follow the remainder of the install wizard


        2.2、Eclipse手动安装

The automatic install is much preferred, but you can also install Ibator manually if you desire. To install manually, download the file IbatorForEclipse1.2.1.zip and unzip the file to some convenient location. After unzipping the update site archive, follow these steps in Eclipse:
  • Take the "Help>Software Updates..." Menu Option
  • Select the "Available Software" Tab
  • Press the "Add Site" button
  • Press the "Local" button
  • Navigate to the location where you unzipped the site archive
  • Press OK
  • Check the box next to "Apache iBATIS Ibator Feature"
  • Press the "Install" button
  • Follow the remainder of the install wizard
3、ibatorConfig.xml文件配置示例(该示例基于Maven项目管理)

引用

<?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>

 <!--配置驱动jar-->
 <classPathEntry
  location="${user.home}/.m2/repository/postgresql/postgresql/8.1-408.jdbc3/postgresql-8.1-408.jdbc3.jar" />

 <ibatorContext id="context1">
  <!--数据库连接-->
  <jdbcConnection driverClass="org.postgresql.Driver"   connectionURL="jdbc:postgresql://127.0.0.1:5432/test_site" userId="test"   password="123456"> </jdbcConnection>

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

  <!--产生Java类,该类的属性与数据库的列名一一对应,targetPackage为产生的类的包名-->
  <javaModelGenerator targetPackage="org.jpxx.test.common.dal.ibatis.model"
   targetProject="test/src/main/java/">
   <property name="enableSubPackages" value="true" />
   <property name="trimStrings" value="true" />
  </javaModelGenerator>

 <!--SqlMap XML 文件-->
  <sqlMapGenerator targetPackage="sqlmap"
   targetProject="test/src/main/resources/">
   <property name="enableSubPackages" value="true" />
  </sqlMapGenerator>

 <!--DAO类的产生配置-->
  <daoGenerator targetPackage="org.jpxx.test.common.dal.ibatis.dao"
   implementationPackage="org.jpxx.sec.common.dal.ibatis.dao.impl"
   targetProject="test/src/main/java/" type="GENERIC-SI">
   <property name="enableSubPackages" value="true" />
  </daoGenerator>

  <!-- 数据库表的相关配置 -->
  <table schema="" tableName="admin" domainObjectName="Admin">
   <property name="useActualColumnNames" value="false" />
   <property name="enableInsert" value="true" />
   <property name="enableSelectByPrimaryKey" value="true" />
   <property name="enableUpdateByPrimaryKey" value="true" />
   <property name="enableDeleteByPrimaryKey" value="true" />
  </table>
  
  <table schema="" tableName="college_image" domainObjectName="Photo">
   <property name="useActualColumnNames" value="false" />
   <property name="enableInsert" value="true" />
   <property name="enableSelectByPrimaryKey" value="true" />
   <property name="enableUpdateByPrimaryKey" value="true" />
   <property name="enableDeleteByPrimaryKey" value="true" />
   
   <property name="enableSelectByExample" value="false" />
   <property name="enableDeleteByExample" value="false" />
   <property name="enableCountByExample" value="false" />
   <property name="enableUpdateByExample" value="false" />
   <property name="selectByExampleQueryId" value="false" />
  </table>
 <!-- 数据库表的相关配置结束 -->

 </ibatorContext>
</ibatorConfiguration>


4、执行Ibator
 
         选中 ibatorConfig.xml 右键Generate iBATIS Artifacts.
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:12018次
    • 积分:237
    • 等级:
    • 排名:千里之外
    • 原创:14篇
    • 转载:1篇
    • 译文:0篇
    • 评论:2条