Abator安装与应用实例(图解)

本文介绍了如何通过Abator插件为Eclipse环境生成实体类、SQL映射文件和DAO实现,包括安装步骤、配置XML文件以及实际应用案例。重点在于自动化生成CRUD操作,减少手动编码工作,提高开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


版本:Myeclipse6.5

首先,让我安装此插件:

Abator for Eclipse Update Site

This is the Abator for Eclipse update site.  If you're not sure what Abator is, then see this pagehttp://ibatis.apache.org/abator.html

If you've already installed a prior version of Abator for Eclipse, then simply run the Eclipse Install/Update tool and any new version will be found automatically.

If you've not already installed Abator, then you can use the built in Eclipse   install support by following these steps:

  1. Take the "Help>Software Updates>Find and Install" Menu Option
  2. Select the "Search for new features to install" radio button, press "Next"
  3. Press the "New Remote Site" button
  4. Enter the following information:   
    Name:
    Abator for Eclipse Update Site
    URL:
    http://ibatis.apache.org/tools/abator
  5. Press OK
  6. Check the box next to "Abator for Eclipse Update Site"
  7. Follow the remainder of the install wizard

以上是官方给的说明,请细读。

2、以下是安装图解:

Help->Sofeware Updates -> find and install

URL:http://ibatis.apache.org/tools/abator

全部勾选

同意协议

Install All

OK,安装完成。


让我试试。

1、首先新建一个JavaProject。

2、新建abatorConfig.xml

 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> <!-- TODO: Add Database Connection Information -->
<jdbcConnection driverClass="???"
connectionURL="???"
userId="???"
password="???">
<classPathEntry location="???" />
</jdbcConnection>

<javaModelGenerator targetPackage="???" targetProject="???" />
<sqlMapGenerator targetPackage="???" targetProject="???" />
<daoGenerator type="IBATIS" targetPackage="???" targetProject="???" />

<table schema="???" tableName="???">
<columnOverride column="???" property="???" />
</table>

</abatorContext>
</abatorConfiguration>

我们需要做的是替换一些???:
1. 填写driverClass(jdbc驱动,例如MySql的就是com.mysql.jdbc.Driver)
2. 填写connectionURL(连接字符串,例如MySql的就是jdbc:mysql://localhost:3306/ibatis)
3. 填写classPathEntry的location(jdbc驱动jar包的位置,例如:lib/mysql-connector-java-3.1.5-gamma-bin.jar)
4. 填写javaModelGenerator,生成的DTO(java model 类)
targetPackage:目标包的位置,如 com.etong.test.daomain
targetProject:目标源文件夹位置,如:..\test\src\main\java\
5. 填写sqlMapGenerator ,生成的xml sqlmap的相关配置
targetPackage:目标位置,如 .表示放在该目标源文件夹的根目录下.
targetProject:目标源文件夹位置,如:..\test\src\main\resources\
6. 填写daoGenerator ,生成的DAO的相关配置
type:生成的dao实现的类型,如果你使用spring的话写SPRING,否则写IBATIS
targetPackage:目标位置,如 com.etong.test.dao
targetProject:目标源文件夹位置,如:..\test\src\main\java\
7. 配置相关数据库的表
schema:数据库schema (如果是oracle就是填写数据库的用户名)
tableName:表名
columnOverride:表的字段名.
修改后的abatorConfig.xml配置文件内容如下:



  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE abatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN" "http://ibatis.apache.org/dtd/abator-config_1_0.dtd" >  
  3. <abatorConfiguration >  
  4.   <abatorContext >  
  5.     <!-- 数据库URL及用户名和密码 -->  
  6.     <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/数据库名?useUnicode=true&characterEncoding=UTF-8" userId="用户名" password="密码" >  
  7.       <!-- JDBC驱动 -->  
  8.       <classPathEntry location="C:\mysql-connector-java-5.1.21-bin.jar" />  
  9.     </jdbcConnection>  
  10.     <!-- targetPackage=实体类(包) targetProject=项目名/src -->  
  11.     <javaModelGenerator targetPackage="com.zt.zs.model" targetProject="TestAbator\src" />  
  12.     <!-- targetPackage=sqlmap(包) targetProject=项目名/src -->  
  13.     <sqlMapGenerator targetPackage="com.zt.config.ibatis.sqlmaps" targetProject="TestAbator\src" />  
  14.     <!-- targetPackage=dao和daoimpl(包) targetProject=项目名/src  type可以是spring ibatis等,看自己需要-->  
  15.     <daoGenerator targetPackage="com.zt.zs.dao" targetProject="TestAbator\src" type="spring" />  
  16.       
  17.     <!-- 要生成的表,可以配置多个,我的下面是配置了一个自动增长ID,这样在dao中会有id是自动增长 -->  
  18.     <!-- ID就会变成如下:SELECT LAST_INSERT_ID() -->  
  19.     <table schema="testDB" tableName="tb_test" domainObjectName="">  
  20.         <property name="useActualColumnNames" value="true"/>  
  21.         <generatedKey column="ID" sqlStatement="MySql" identity="true" />  
  22.         <columnOverride column="ID" property="ID"/>  
  23.     </table>   
  24.       
  25.   </abatorContext>  
  26. </abatorConfiguration>  


 我目前的做法是,在用Abator生成出来的在包装一层。其实Abator生成出来的确实很乱,但是也是很有用的,修改修改就可以用了。(我目前没有修改,我只要了Abator自动生生成出来的CURD,其它业务在在别的sqlmap中配置,CRUD可以实现0手工修改,可以通过此工具维护,排除CRUD的需要编码人自动配置编写)

如果在生产环境下,能够满足自动生成我们业务需要的sqlmap,还有待于学习。目前,没有找到。
 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值