iBATIS的Eclipse插件Abator使用方法
<?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 generatorSet="Java5"><!– TODO: Add Database Connection Information –>
<jdbcConnection driverClass="org.gjt.mm.mysql.Driver"
connectionURL="???"
userId="???" password="???">
<classPathEntry
location="???" />
</jdbcConnection>
<javaModelGenerator targetPackage="???"
targetProject="???" />
<sqlMapGenerator targetPackage="???"
targetProject="???" />
<daoGenerator type="IBATIS"
targetPackage="???"
targetProject="???" />
<table schema="???" tableName="???">
<generatedKey identity="true" column="???"
sqlStatement="???" />
<columnOverride column="???" javaType="java.sql.Date"
jdbcType="date" />
</table>
</abatorContext>
</abatorConfiguration>
所有的参数都是写在<abatorConfiguration>这个根节点中,下面可以用 <abatorContext>来生成个自的iBATIS配置文件、Java Bean和DAO
abatorContext的一个属性generatorSet有3个选项Legacy、Java2、Java5
Legacy:如果没有generatorSet属性的话,默认是Legacy。但并不推荐使用Legacy因为它在生成Example类(用于查询条件)的时候有很多限制,他将查询条件写在sqlMap配置文件中,将查询值写在Example中,这样就对修改产生一些困难。
Java2和Java5:他们只支持iBATIS 2.20以上的版本。在以这个模式成生的Example文件中包含了查询条件和查询值。这样修改就方便多了,对于用join的select时的查询就更方便了,自己可以定义查询条件,自由度高了很多(对于join的and查询可能还得自己修改一下Example代码)。对于or和and的应用Legacy的限制就比较大了。
<jdbcConnection>描述了JDBC的属性和其jar包的位置.
<javaModelGenerator>、 <sqlMapGenerator>、 <daoGenerator>描述了个自生成的位置。<daoGenerator>中type属性则用来告诉abator生成的DAO是用于iBATIS还是SPRING等容器。
<table>告诉abator生成那个table的sqlMap。
<generatedKey>来告诉abator那些列需要自动返回值(当插入的时候可以返回插入记录的主键,这对有外键的数据库极其有用)identity默认为false,则在sqlMap配置文件中<selectKey>的位置在sql命令前面,所以identity应该改为true。sqlStatement属性则填入各类数据库的返回值函数:
Cloudscape | This will translate to VALUES IDENTITY_VAL_LOCAL() |
---|---|
DB2 | This will translate to VALUES IDENTITY_VAL_LOCAL() |
Derby | This will translate to VALUES IDENTITY_VAL_LOCAL() |
HSQLDB | This will translate to CALL IDENTITY() |
MySql | This will translate to SELECT LAST_INSERT_ID() |
SqlServer | This will translate to SELECT SCOPE_IDENTITY() |
<columnOverride>告诉abator那些列是需要特殊处理的,对于date这种比较复杂的类型,可以用它来指定映射(用jdbctype和javatype属性来指定)。
还有一些不大用的到的属性这里就不介绍了。