欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

iBatisNet入门示例源码详解 DataMapperiBATISApache软件测试XML 

程序员文章站 2022-05-09 19:52:57
...
下载ibatis软件包(http://ibatis.apache.org/dotnetdownloads.html)。

2. 创建测试数据库,并在数据库中创建一个Person 表,其中包含三个字段:

NameTypeSize

PER_IDLongInteger4 not null

PER_FIRST_NAMEnvarchar40 not null

PER_LAST_NAMEnvarchar40 not null

PER_BIRTH_DATE DateTime8

PER_WEIGHT_KGfloat8

PER_HEIGHT_Mfloat8

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] &lt;%X{auth}&gt; - %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 基础代码包括:

1IBatisNet 实例配置

一个典型的配置文件如下(具体配置项目的含义见后):

iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML <?xml version="1.0" encoding="utf-8"?>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<!-- Rem : If used via a DataAccess context, properties tag will be ignored
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML  <properties resource="../../database.config"/>
-->
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<properties embedded="database.config, IBatisNetDemo"/>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<settings>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<setting useStatementNamespaces="${useStatementNamespaces}"/>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<setting cacheModelsEnabled="true"/>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<setting validateSqlMap="false"/>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
</settings>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<!-- Optional if resource -->
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<providers embedded="providers.config,IBatisNetDemo"/>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<!-- ==== SqlClient configuration ========= -->
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<!-- Rem : If used via a DataAccess context, database tag will be ignored -->
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<database>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<!-- Optional ( default ) -->
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<provider name="sqlServer1.1"/>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<dataSource name="iBatisNet" connectionString="data source=localhost;database=Northwind;user id=sa;password=;connection reset=false;connection lifetime=5; min pool size=1; max pool size=50"/>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
</database>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<sqlMaps>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<!-- user via embedded-->
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
<sqlMap embedded="Map.SqlClient.Person.xml,IBatisNetDemo"/>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
</sqlMaps>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
</sqlMapConfig>
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 

2. PO(Plain Ordinary Object)

下面是我们用作示例的一个PO:

iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML [Serializable]
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
public class Person
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
...{
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
private int id;
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
private string firstName;
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
private string lastName;
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
private DateTime? birthDate;
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
private double? weightInKilograms;
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
private double? heightInMeters;
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
public Person() ...{
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
public int Id
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
...{
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
get ...{ return id; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
set ...{ id = value; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML  }

iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
public string FirstName
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
...{
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
get ...{ return firstName; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
set ...{ firstName = value; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML  }

iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
public string LastName
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
...{
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
get ...{ return lastName; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
set ...{ lastName = value; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML  }

iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
public DateTime? BirthDate
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
...{
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
get ...{ return birthDate; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
set ...{ birthDate = value; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML  }

iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
public double? WeightInKilograms
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
...{
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
get ...{ return weightInKilograms; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
set ...{ weightInKilograms = value; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML  }

iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
public double? HeightInMeters
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
...{
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
get ...{ return heightInMeters; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
set ...{ heightInMeters = value; }
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML 
iBatisNet入门示例源码详解
            
    
    
        DataMapperiBATISApache软件测试XML  }
color: #

相关推荐