Ibatis自动生成工具-Abator

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/k_scott/article/details/8281837

OS:win7 (64bit)

JDK:jdk1.6.0_23 (64bit)

IDE:MyEclipse6.5 (实际使用在MyEclipse8.5,为了演示方便用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 >
    <!-- 数据库URL及用户名和密码 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/数据库名?useUnicode=true&characterEncoding=UTF-8" userId="用户名" password="密码" >
      <!-- JDBC驱动 -->
      <classPathEntry location="C:\mysql-connector-java-5.1.21-bin.jar" />
    </jdbcConnection>
    <!-- targetPackage=实体类(包) targetProject=项目名/src -->
    <javaModelGenerator targetPackage="com.zt.zs.model" targetProject="TestAbator\src" />
    <!-- targetPackage=sqlmap(包) targetProject=项目名/src -->
    <sqlMapGenerator targetPackage="com.zt.config.ibatis.sqlmaps" targetProject="TestAbator\src" />
    <!-- targetPackage=dao和daoimpl(包) targetProject=项目名/src  type可以是spring ibatis等,看自己需要-->
    <daoGenerator targetPackage="com.zt.zs.dao" targetProject="TestAbator\src" type="spring" />
    
    <!-- 要生成的表,可以配置多个,我的下面是配置了一个自动增长ID,这样在dao中会有id是自动增长 -->
    <!-- ID就会变成如下:SELECT LAST_INSERT_ID() -->
    <table schema="testDB" tableName="tb_test" domainObjectName="">
        <property name="useActualColumnNames" value="true"/>
        <generatedKey column="ID" sqlStatement="MySql" identity="true" />
        <columnOverride column="ID" property="ID"/>
    </table> 
    
  </abatorContext>
</abatorConfiguration>


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

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

 

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页