IBatisNet1.5学习--配置篇

       最近准备学习IbatisNet1.5,顺便将学习的过程记录下来,整个过程的环境是VS2005+IBatisNet1.5,下面首先我们来看一下IBatisNet的配置.
        IBatisNet DataMapper是通过XML文件来配置的,配置文件名称我们通常默认为SqlMap.Config,配置文件中指定了我们项目的数据库连接字符串,以及数据库表的映射文件等等.
       下面我们来看一个很简单的配置文件

<?xml version="1.0" encoding="utf-8"?>
<sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper" 
              xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance">

    
<settings>
        
<setting useStatementNamespaces="false"/>
        
<setting cacheModelsEnabled="true"/>
    
</settings>
  
    
<providers resource="providers.config"/>
  
    
<!-- Database connection information -->
    
<database>
        
<provider name="sqlServer1.1"/>
        
<dataSource name="IBatisNet" connectionString="server=.;database=IBatisNet;uid=sa;pwd=;"/>
    
</database>

    
<sqlMaps>
        
<sqlMap resource="SqlMap/NewsType.xml" />
    
</sqlMaps>
</sqlMapConfig>

下面来简单说一下每个配置节的属性及作用:
1.Settings

Attribute Description
cacheModelsEnabled

是否启用DataMapper的缓存机制,针对全部的SqlMap
Example:
cacheModelsEnabled=”true” 
Default:true (enabled)  

useStatementNamespaces

是否使用Satement命名空间,这里的命名空间指的是映射文件中sqlMap节点的namespace属性
Example:useStatementNamespaces =”false” 
Default:true (disabled)  
validateSqlMap

是否启用SqlMapConfig.xsd schema验证映射文件.
Example:validateSqlMap =”false” 
Default:true (disabled)  

useReflectionOptimizer

是否启用反射来获取实体类的属性的值

Example:useReflectionOptimizer=”true” 
Default:true (enabled) 


2.properties

Attribute Description
resource

指定properties文件从应用程序根目录进行加载

url

指定properties文件从相对路径进行加载

embedded

指定properties文件可作为程序集的资源文件进行加载


3.providers
用于提供数据库驱动配置文件的文件名和路径,其子元素的含义同上

4.database
其中包括两个子元素,分别是provider和datasource
如果在providers.config文件中指定了默认的数据库驱动,那么provider节点就不需要设置了,它的作用是在换数据库驱动时不需要修改providers.config文件。
Example:

<provider name="sqlServer1.1"/>

datasource节点用于指定ADO.NET Connection String.
Example:
<dataSource name="IBatisNet" connectionString="server=.;database=IBatisNet;uid=sa;pwd=;"/>

5.sqlMap

该节点下需列出所有应用程序使用的DataMapper的实例,也就是映射文件。
Example:
<sqlMaps>
        
<sqlMap resource="SqlMap/NewsType.xml" />
    
</sqlMaps>

posted on 2006-08-08 18:02  Daniel Pang  阅读(6042)  评论(5编辑  收藏  举报

导航