下载ibatis软件包(http://ibatis.apache.org/dotnetdownloads.html)。
2. 创建测试数据库,并在数据库中创建一个Person 表,其中包含三个字段:
Name Type Size
PER_ID Long Integer 4 not null
PER_FIRST_NAME nvarchar 40 not null
PER_LAST_NAME nvarchar 40 not null
PER_BIRTH_DATE DateTime 8
PER_WEIGHT_KG float 8
PER_HEIGHT_M float 8
3. 为了在开发过程更加直观,我们需要将ibatisnet日志打开以便观察ibatinets运作的细节。
ibatisnet采用IBatisNet.Common.Logging.Log4Net,就是使用Log4Net纪录日志的包装。在Web.config中增加下面的配置内容:
<configSections>
<sectionGroup name="iBATIS">
<section name="logging" type="IBatisNet.Common.Logging.ConfigurationSectionHandler, IBatisNet.Common" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<iBATIS>
<logging>
<logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA, IBatisNet.Common.Logging.Log4Net">
<arg key="configType" value="inline" />
<arg key ="showLogName" value="true" />
<arg key ="showDataTime" value="true" />
<arg key ="level" value="ALL" />
<arg key ="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:SSS" />
</logFactoryAdapter>
</logging>
</iBATIS>
<!-- This section contains the log4net configuration settings -->
<log4net>
<!-- Define some output appenders -->
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="log.txt" />
<param name="AppendToFile" value="true" />
<param name="MaxSizeRollBackups" value="2" />
<param name="MaximumFileSize" value="100KB" />
<param name="RollingStyle" value="Size" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]"r"n" />
<param name="Footer" value="[Footer]"r"n" />
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n" />
</layout>
</appender>
<!-- Set root logger level to ERROR and its appenders -->
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="ConsoleAppender" />
</root>
<!-- Print only messages of level DEBUG or above in the packages -->
<logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.LazyLoadList">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.DaoSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataMapper.SqlMapSession">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.Common.Transaction.TransactionScope">
<level value="DEBUG" />
</logger>
<logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
<level value="DEBUG" />
</logger>
</log4net>
构建IBatisNet基础代码
IBatisNet 基础代码包括:
1. IBatisNet 实例配置
一个典型的配置文件如下(具体配置项目的含义见后):
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
2. PO(Plain Ordinary Object)
下面是我们用作示例的一个PO:
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
3.映射文件
与Hibernate 不同。因为需要人工编写SQL 代码,IBatisNet 的映射文件一般采
用手动编写(通过Copy/Paste,手工编写映射文件也并没想象中的麻烦)。
针对上面PO 的映射代码如下:
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
从上面的映射文件可以看出,通过<insert>、<delete>、<update>、
<select>四个节点,我们分别定义了针对Person 对象的增删改查操作。在这
四个节点中,我们指定了对应的SQL 语句,以update节点为例:
……
<update id=" UpdatePerson" ⑴
parameterClass="Person"> ⑵
<![CDATA[⑶
update Person set ⑷
PER_FIRST_NAME =#FirstName#,⑸
PER_LAST_NAME =#LastName#, ⑹
PER_BIRTH_DATE =#BirthDate#,
PER_WEIGHT_KG=#WeightInKilograms#,
PER_HEIGHT_M=#HeightInMeters#
where
PER_ID = #Id# ⑺]]>
</update>
……
⑴ ID
指定了操作ID,之后我们可以在代码中通过指定操作id 来执行此节点所定
义的操作,如:
SqlMap.Update("UpdatePerson", person);
ID设定使得在一个配置文件中定义两个同名节点成为可能(两个update节
点,_____以不同id区分)
⑵ parameterClass
指定了操作所需的参数类型,此例中update 操作以
IBatisNetDemo.Domain.Person类型的对象作为参数,目标是将提供的Person
实例更新到数据库。
parameterClass="Person"中,user为“IBatisNetDemo.Domain.Person”
类的别名,别名可通过typeAlias节点指定,如示例配置文件中的:
<typeAlias alias="Person" type="IBatisNetDemo.Domain.Person,IBatisNetDemo" />⑶ <![CDATA[……]]>
通过<![CDATA[……]]>节点,可以避免SQL 中与XML 规范相冲突的字符对
XML映射文件的合法性造成影响。
⑷ 执行更新操作的SQL,这里的SQL 即实际数据库支持的SQL 语句,将由
IBatisNet填入参数后交给数据库执行。
⑸ SQL中所需的用户名参数,“# FirstName #”在运行期会由传入的Person对象的FirstName
属性填充。
⑹ SQL 中所需的用户性别参数“# LastName #”,将在运行期由传入的user 对象的
LastName属性填充。
⑺ SQL中所需的条件参数“#id#”,将在运行期由传入的Person对象的Person属性
填充。
对于这个示例,IBatisNet在运行期会读取id 为“UpdatePerson”的update节点
的SQL定义,并调用指定的user对象的对应getter方法获取属性值,并用此
属性值,对SQL中的参数进行填充后提交数据库执行。
此例对应的应用级代码如下,其中演示了IBatisNet SQLMap的基本使用方法:
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://www.51aspx.com/Images/OutliningIndicators/None.gif)
其中,SqlMapper是IbatisNet运作的核心,所有的操作均通过SqlMapper实例完成。这个例子中我将所有的配置文件按照资源文件方式存放,所以从程序集去加载sqlmap.config文件。