1. Abator automatically generates configuration: Abator automatically generates ibatis configuration file, mode, sqlMap, dao, bean instance preparation: 1. Install Eclipse plug-in: Eclipse3.1, jdk1.4 or above is required to install the abator plug-in eclipse menu bar on eclipse- -> help --> Software Updates --> Find And nstall... Select "Search for new features to install" in the pop-up dialog box and click "next" in the dialog box and click the button New Remort Site... In Fill in http://ibatis.apache.org/tools/abator in the URL input box in the pop-up dialog box, and write whatever you want in the Name input box. Click Finish, install the plug-in, and then restart eclipse 2. Create a new Abator Configuration File in the eclipse project named: abatorConfig.xml (can be customized). After the generated xml is modified as follows:
- <!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="oracle.jdbc.driver.OracleDriver"
- connectionURL="jdbc:oracle:thin:@198.17.1.1:1521:ORCL" userId="untodo" password="password" >
- <classPathEntry location="E:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />
- </jdbcConnection>
- <javaModelGenerator targetPackage="com.mochasoft.model" targetProject="downAttachdemo/src">
- <property name="enableSubPackages" value="true" />
- </javaModelGenerator>
- <sqlMapGenerator targetPackage="sqlmap" targetProject="downAttachdemo/conf>
- <property name="enableSubPackages" value="true" />
- </sqlMapGenerator>
- <daoGenerator targetPackage="com.mochasoft.dao" targetProject="downAttachdemo/src" type="ibatis">
- <property name="enableSubPackages" value="true" />
- </daoGenerator>
- <table schema="untodo" tableName="APP" >
- <columnOverride column="SYS_ID" property="sysId" />
- <columnOverride column="SYS_NAME" property="sysName" />
- </table>
- </abatorContext>
- </abatorConfiguration>
3、在配置文件上点解右键,选择 “Generate iBatis Artifacts”
说明:driverClass:数据库连接驱动类
connectionURL:数据库连接地址
userId:数据库用户
passwor:数据库密码
location:数据库驱动jar包地址(本地)
targetPachage:自动生成的包的地址,(可以是已建好的,也可以是未建的)
targetProject:自动生成的项目名
type:生成dao文件的类型,可选择IBATIS、SPRING、GENERIC-CI、GENERIC-SI。默认使用GENERIC-CI
- <property name="enableSubPackages" value="false" />
是否在包名后加上scheme名称
schema:Oracle的话填写用户名
tableName:要生成的表名
column:表字段名
property:表映射生成类属性名
talbe下的字段说明:
tableName 数据库表明,据说可以包含SQL通配符%和_。
domainObjectName 数据库表对应的数据对象名称,默认使用表名作为对象名称。
- <property name="useActualColumnNames" value="true"/>
对象的属性名是否使用字段名称
- <generatedKey column="ID" sqlStatement="DB2" identity="true" />
column 自增长或使用sequence生成的字段名
sqlStatement 生成字段的sql片段或其简称(参考官方文档)
identity true表示后生成,false表示预生成
例如:
- postgresql:<generatedKey
- column="lid"
- sqlStatement="select nextval('tb000000producttype_lid_seq')"
- identity="false" />
- sqlserver:<generatedKey
- column="lid"
- sqlStatement="SqlServer"
- identity="true" />
- oracle:<generatedKey
- column="lid"
- sqlStatement="select tb000000producttype_lid_seq.nextval from dual"
- identity="false" />
- <columnOverride column="DATE_FIELD" property="startDate" />
column 字段名
property 字段对应的属性名。(默认使用字段名的)
javaType 对应的Java类型
jdbcType 对应的jdbc类型
这里的设置覆写javaTypeResolver中的指定
- <ignoreColumn column="FRED" />
column database field to ignore
- <columnRenamingRule searchString="^CUST_" replaceString="" />
The mapping relationship between database field names and object property names. It's a replacement process.
http://jadethao.iteye.com/blog/1725374