首先,让我安装此插件:
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:
- Take the "Help>Software Updates>Find and Install" Menu Option
- Select the "Search for new features to install" radio button, press "Next"
- Press the "New Remote Site" button
- Enter the following information:
-
Name:
- Abator for Eclipse Update Site URL:
- http://ibatis.apache.org/tools/abator
- Press OK
- Check the box next to "Abator for Eclipse Update Site"
- 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配置文件内容如下:
- <?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,还有待于学习。目前,没有找到。