1.       简介
ibatisapache的一个开源项目,一个O/R Mapping解决方案。特点是小巧、上手快。官方网站:[url]http://ibatis.apache.org[/url]
 
2.       搭建环境:导入相关jar
 
3.       配置文件
l         jdbc连接的属性文件
l         总配置文件
l         关于每个实体的映射文件(map文件)
 
(1)    属性文件:sqlMap.properties
dirver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
username=test
password=test
 
(2)    总配置文件:SqlMapConfig.xml
<?xml version=”1.0” encoding=”utf-8” ?>
<!DOCTYPE….>
<sqlMapConfig>
          <properties resource=”sqlMap.properties” />
          <transactionManager type=”JDBC”>
                 <dataSource type=”SIMPLE”>
                        <property name=”JDBC.Driver” value=”${dirver}” />
                        <property name=”JDBC.ConnectionURL” value=”${url}” />
                        <property name=”JDBC.Username” value=”${username}” />
                        <property name=”JDBC.Password” value=”${password}” />
</dataSource>
</transactionManager>
<sqlMap resource=”student.xml” />
</sqlMapConfig>
 
(3)    实体映射文件:student.xml
<?xml version=”1.0” encoding=”utf-8” ?>
<!DOCTYPE….>
   <sqlMap>
                <resultMap id=”studentResult” class=”Student”>
                <result property=”sid” column=”sid” />
                       <result property=”sname” column=”sname” />
                       <result property=”major” column=”major” />
                       <result property=”birth” column=”birth” />
</resultMap>
    </sqlMap>
4.       读取配置代码:
private static SqlMapClient sqlMapClient = null;
 
static{
        try{
               Reader reader = Resource.getResourceAsReader
                                             (“com/wangsy/SqlMapConfig.xml”);
                sqlMapClient = SqlMapClientBuilder.
                                         buildSqlMapClient(reader);
                reader.close();
}catch(IOException e){
 
}
}