---
title: "ibatis2.3入门"
author: "awfrun"
date: "2011-03-28T22:54:09Z"
tags: []
categories: ["企业架构"]
slug: "ibatis2-3"
draft: false
lastmod: "2011-03-28T22:55:31Z"
id: 977999
url: "https://awfrun.iteye.com/blog/977999"
---

1.需要的包在附件中

2.eclipse自动生成映射文件

Abator安装

Abator 的官方网站：[http://ibatis.apache.org/ibator.html](http://ibatis.apache.org/ibator.html)

在eclipse的菜单栏中可以看到: File &gt; New &gt; Abator  for iBATIS Configuration File,  即安装成功

自动生成abatorConfig.xml

 

替换abatorConfig.xml中的？？？：

①. 填写driverClass（jdbc驱动，例如oracle的就是oracle.jdbc.driver.OracleDriver）  
②. 填写connectionURL（连接字符串，例如oracle的就是jdbc:oracle:thin:@localhost:1521:orcl）  
③. 填写classPathEntry的location（jdbc驱动jar包的位置，例如D:/myproject/test/WEB-INF/lib/ojdbc14.jar）  
④. 填写javaModelGenerator，生成的DTO（java model 类）  
    targetPackage：目标包的位置，如 com.test.model  
    targetProject：目标工程名称，填写配置文件所在的eclipse工程名，如test/src  
⑤. 填写sqlMapGenerator ，生成的xml sqlmap的相关配置  
    targetPackage：目标位置，如 com.test.sqlmap  
    targetProject：目标工程名称，填写配置文件所在的eclipse工程名，如test/src  
⑥. 填写daoGenerator ，生成的DAO的相关配置  
    type：生成的dao实现的类型，如果你使用spring的话写SPRING，否则写IBATIS  
    targetPackage：目标位置，如 com.test.dao  
    targetProject：目标工程名称，填写配置文件所在的eclipse工程名，如test/src  
⑦. 配置相关数据库的表  
    schema：数据库schema，oracle就是填写数据库的用户名，如test  
    tableName：表明，如ttest  
    catalog：数据库名，如orcl  
    注释掉&lt;columnOverride column="???" property="???" /&gt;，不写columnOverride的话生成所有字段

 

 

```
<?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 >
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/test?useUnicode=true&amp;characterEncoding=gbk" userId="root" password="admin" >
      <classPathEntry location="D:\soft\jar\mysql-connector-java-5.0.0.jar" />
    </jdbcConnection>
    <javaModelGenerator targetPackage="com.test.model" targetProject="ibatis/src" />
    <sqlMapGenerator targetPackage="com.test.sqlmap " targetProject="ibatis/src" />
    <daoGenerator targetPackage=" com.test.dao" targetProject="ibatis/src" type="GENERIC-CI" />
    <table schema="test" tableName="admin" >
    <!--
      <columnOverride column="???" property="???" />
      -->
    </table>
  </abatorContext>
</abatorConfiguration>
```

 

其它说明：

type        生成dao文件的类型，可选择IBATIS、SPRING、GENERIC-CI、GENERIC-SI。默认使用GENERIC-CI  
                      dao类在构造器中获取 SqlMapClient