使用Abator自动生成IBatis代码

本文介绍如何在Eclipse IDE中安装Abator插件并进行配置,通过示例展示了如何利用该插件生成针对MySQL数据库的iBatis相关代码。

1 安装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

2 下面测试一下功能
(1). 新建一个java工程
(2). 在eclipse菜单栏中兴建一个 abator 配置文件
    File -->  Abator  for  iBatis Configration File
(3). 系统自动生成的abatorConfig.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 >
    <jdbcConnection driverClass="???" connectionURL="???" userId="???" password="???" >
      <classPathEntry location="???" />
    </jdbcConnection>
    <javaModelGenerator targetPackage="???" targetProject="???" />
    <sqlMapGenerator targetPackage="???" targetProject="???" />
    <daoGenerator targetPackage="???" targetProject="???" type="GENERIC-CI" />
    <table schema="???" tableName="???" >
      <columnOverride column="???" property="???" />
    </table>
  </abatorContext>
</abatorConfiguration>

(4).将?替代为我们需要的内容(以我的一个使用MYSQL的实验项目为例)

<?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 id="mysql" generatorSet="Java5" >
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mydb" userId="root" password="123456" >
      <classPathEntry location="D:/workspace/AbatorProject/lib/jdbc/mysql-connector-java-5.1.6-bin.jar" />
    </jdbcConnection>
    <javaModelGenerator targetPackage="com.dmh.model" targetProject="AbatorProject" />
    <sqlMapGenerator targetPackage="com.dmh.sqlmap" targetProject="AbatorProject" />
    <daoGenerator type="IBATIS" targetPackage="com.dmh.dao" targetProject="AbatorProject"  />
    <table schema="mydb" tableName="ottawa_question" >
    </table>
  </abatorContext>
</abatorConfiguration>

(5).在配置文件上点解右键,选择 “Generate iBatis Artifacts”,代码生成成功。 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值