---
title: "Abator自动生成ibatis的相关配置和类(转)"
author: "javaEEdevelop"
date: "2012-11-14T21:45:31Z"
tags: []
categories: ["开源软件"]
slug: "abator-ibatis"
draft: false
lastmod: "2012-11-14T21:46:31Z"
id: 1725831
url: "https://javaeedevelop.iteye.com/blog/1725831"
---

**一、abator自动生成配置：**   
abator自动生成ibatis的配置文件、mode、sqlMap、dao、bean实例   
准备：   
1、安装Eclipse插件：   
     要求eclipse3.1，jdk1.4以上   
     在eclipse上安装abator插件   
       eclipse菜单栏 --&gt; help --&gt; Software Updates --&gt; Find And nstall...   
     在弹出的对话框中选择 “Search for new features to install” 然后点击 “next”   
    在对话框中点击按钮 New Remort Site... 在弹出的对话框中的URL输入框中填写 http://ibatis.apache.org/tools/abator ，Name输入框就随便写些什么了。   
    点击Finish，安装插件，然后重新启动eclipse      
2、在eclipse项目中新建Abator Configuration File，名为：abatorConfig.xml（可以自定义）。   
生成xml修改之后如下： 

Xml代码      [![收藏代码](http://jadethao.iteye.com/images/icon_star.png)]()

01. &lt;!DOCTYPE abatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN" "http://ibatis.apache.org/dtd/abator-config\_1\_0.dtd" &gt;
02. &lt;abatorConfiguration &gt;
03. &lt;abatorContext &gt;
04. &lt;jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
05. connectionURL="jdbc:oracle:thin:@198.17.1.1:1521:ORCL" userId="untodo" password="password" &gt;
06. &lt;classPathEntry location="E:\\oracle\\product\\10.2.0\\db\_1\\jdbc\\lib\\ojdbc14.jar" /&gt;
07. &lt;/jdbcConnection&gt;
08. &lt;javaModelGenerator targetPackage="com.mochasoft.model" targetProject="downAttachdemo/src"&gt;
09. &lt;property name="enableSubPackages" value="true" /&gt;
10. &lt;/javaModelGenerator&gt;
11. &lt;sqlMapGenerator targetPackage="sqlmap" targetProject="downAttachdemo/conf&gt;
12. &lt;property name="enableSubPackages" value="true" /&gt;
13. &lt;/sqlMapGenerator&gt;
14. &lt;daoGenerator targetPackage="com.mochasoft.dao" targetProject="downAttachdemo/src" type="ibatis"&gt;
15. &lt;property name="enableSubPackages" value="true" /&gt;
16. &lt;/daoGenerator&gt;
17. &lt;table schema="untodo" tableName="APP" &gt;
18. &lt;columnOverride column="SYS\_ID" property="sysId" /&gt;
19. &lt;columnOverride column="SYS\_NAME" property="sysName" /&gt;
20. &lt;/table&gt;
21. &lt;/abatorContext&gt;
22. &lt;/abatorConfiguration&gt;

3、在配置文件上点解右键，选择 “Generate iBatis Artifacts” 

说明：driverClass：数据库连接驱动类   
      connectionURL：数据库连接地址   
      userId:数据库用户   
      passwor:数据库密码   
      location:数据库驱动jar包地址（本地）   
      targetPachage:自动生成的包的地址，（可以是已建好的，也可以是未建的）   
      targetProject:自动生成的项目名   
      type：生成dao文件的类型，可选择IBATIS、SPRING、GENERIC-CI、GENERIC-SI。默认使用GENERIC-CI 

Xml代码      [![收藏代码](http://jadethao.iteye.com/images/icon_star.png)]()

1. &lt;property name="enableSubPackages" value="false" /&gt;

  是否在包名后加上scheme名称   
schema：Oracle的话填写用户名   
tableName:要生成的表名   
column:表字段名   
property：表映射生成类属性名   
talbe下的字段说明：     
   tableName 数据库表明，据说可以包含SQL通配符%和\_。   
   domainObjectName 数据库表对应的数据对象名称，默认使用表名作为对象名称。       

Xml代码      [![收藏代码](http://jadethao.iteye.com/images/icon_star.png)]()

1. &lt;property name="useActualColumnNames" value="true"/&gt;

对象的属性名是否使用字段名称 

Xml代码      [![收藏代码](http://jadethao.iteye.com/images/icon_star.png)]()

1. &lt;generatedKey column="ID" sqlStatement="DB2" identity="true" /&gt;

    
    column    自增长或使用sequence生成的字段名   
              sqlStatement 生成字段的sql片段或其简称(参考官方文档)   
              identity    true表示后生成，false表示预生成   
               例如：   
  

Sql代码      [![收藏代码](http://jadethao.iteye.com/images/icon_star.png)]()

01. postgresql：&lt;generatedKey
02. column="lid"
03. sqlStatement="select nextval('tb000000producttype\_lid\_seq')"
04. identity="false" /&gt;
05. sqlserver：&lt;generatedKey
06. column="lid"
07. sqlStatement="SqlServer"
08. identity="true" /&gt;
09. oracle：&lt;generatedKey
10. column="lid"
11. sqlStatement="select tb000000producttype\_lid\_seq.nextval from dual"
12. identity="false" /&gt;

Xml代码      [![收藏代码](http://jadethao.iteye.com/images/icon_star.png)]()

1. &lt;columnOverride column="DATE\_FIELD" property="startDate" /&gt;

        column 字段名   
         property 字段对应的属性名。(默认使用字段名的)   
         javaType 对应的Java类型   
         jdbcType 对应的jdbc类型       
        这里的设置覆写javaTypeResolver中的指定    

Xml代码      [![收藏代码](http://jadethao.iteye.com/images/icon_star.png)]()

1. &lt;ignoreColumn column="FRED" /&gt;

  column    需要忽略的数据库字段  

Xml代码      [![收藏代码](http://jadethao.iteye.com/images/icon_star.png)]()

1. &lt;columnRenamingRule searchString="^CUST\_" replaceString="" /&gt;

  数据库字段名称到对象属性名称的影射关系。就是一个替换处理。 

 

原址(http://jadethao.iteye.com/blog/1725374);