IBatisNet1.5学习--配置篇
?????? 最近準備學習IbatisNet1.5,順便將學習的過程記錄下來,整個過程的環境是VS2005+IBatisNet1.5,下面首先我們來看一下IBatisNet的配置.
??????? IBatisNet DataMapper是通過XML文件來配置的,配置文件名稱我們通常默認為SqlMap.Config,配置文件中指定了我們項目的數據庫連接字符串,以及數據庫表的映射文件等等.
?????? 下面我們來看一個很簡單的配置文件
<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)??
是否啟用反射來獲取實體類的屬性的值
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>
轉載于:https://www.cnblogs.com/pw/archive/2006/08/08/470060.html
總結
以上是生活随笔為你收集整理的IBatisNet1.5学习--配置篇的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ASP.NET2.0中配置文件的加密与解
- 下一篇: 大批量执行webservice出现“无法