<?xml version="1.0" encoding="utf-8"?>
<sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<!-- Rem : If used via a DataAccess context, properties tag will be ignored
<properties resource="../../database.config"/> -->
<properties embedded="database.config, IBatisNetDemo"/>
<settings>
<setting useStatementNamespaces="${useStatementNamespaces}"/>
<setting cacheModelsEnabled="true"/>
<setting validateSqlMap="false"/>
</settings>
<!-- Optional if resource -->
<providers embedded="providers.config,IBatisNetDemo"/>
<!-- ==== SqlClient configuration ========= -->
<!-- Rem : If used via a DataAccess context, database tag will be ignored -->
<database>
<!-- Optional ( default ) -->
<provider name="sqlServer1.1"/>
<dataSource name="iBatisNet" connectionString="data source=${datasource};database=${database};user id=${userid};password=${password};connection reset=false;connection lifetime=5; min pool size=1; max pool size=50"/>
</database>
<sqlMaps>
<!-- user via embedded-->
<sqlMap embedded="Map.SqlClient.Person.xml,IBatisNetDemo"/>
</sqlMaps>
</sqlMapConfig>
1. properties节点
可以根据需要配置一些常量属性。如果这些属性有很多的话可以单独写一个文件里面,再通过resource(或url, embedded分别是引用url和编译在程序中的资源文件)属性引用进来
properties 节点参数
参数 |
描述 |
resource |
指定the properties文件从application的根目录进行加载 resource="properties.config" |
url |
指定the properties文件从文件的绝对路径进行加载 url="c:\Web\MyApp\Resources\properties.config" -or- url="file://c:\Web\MyApp\Resources\properties.config" |
embedded |
指定文件可以作为程序集的资源文件进行加载' embedded=" database.config, IBatisNetDemo” |
上面例子中Properties文件的配置如下:
<?xml version="1.0" encoding="utf-8" ?>
<settings>
<!-- User application and configured property settings go here.-->
<!-- To run tests, create a file named DataBase.config
with your own value for datasource.
(don't included it in the solution and don't commit it in SVN)
-->
<add key="userid" value="sa" />
<add key="password" value="" />
<add key="database" value="Northwind" />
<add key="datasource" value="localhost" />
<add key="selectKey" value="select @@IDENTITY as value" />
<add key="directory" value="Maps" />
<add key="useStatementNamespaces" value="false" />
</settings>
下面解释一下这个文件的节点参数
Property节点参数
参数 |
描述 |
key |
定义key (variable) 名字 key="username"
|
value |
定义DataMapper 中使用的 key的值 value="mydbuser"
|
2. setting节点
Setting节点参数
参数 |
|