iBatisNet入门示例源码详解 DataMapperiBATISApache软件测试XML
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] <%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 实例配置
一个典型的配置文件如下(具体配置项目的含义见后):
<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=localhost;database=Northwind;user id=sa;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>
2. PO(Plain Ordinary Object)
下面是我们用作示例的一个PO:
public class Person
{
private int id;
private string firstName;
private string lastName;
private DateTime? birthDate;
private double? weightInKilograms;
private double? heightInMeters;
public Person() {
public int Id
{
get { return id; }
set { id = value; }
}
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public DateTime? BirthDate
{
get { return birthDate; }
set { birthDate = value; }
}
public double? WeightInKilograms
{
get { return weightInKilograms; }
set { weightInKilograms = value; }
}
public double? HeightInMeters
{
get { return heightInMeters; }
set { heightInMeters = value; }
}color: #
相关推荐
iBatisNet入门示例源码
项目名称:IBatisNEt实践项目 功能描述:利用IBatis NET实现对单表的增删改查 操作 开发工具:vs2005,SQL2005 开发环境:WindowServer2003(WindowXP下也可运行) 开发语言:C#,JQuery,ASP.NET 架构模式:BS架构 (备注:...
IBatisNet 源码直接引用,以.dll结尾,可以直接引用
摘要:.NET源码,控件组件,iBatisNet,GridView,DetailsView iBatisNet入门源码,练习GridView和DetailsView操作,环境,利用配置IBatisNet操作GridView和DetailsView的源码例子,里面还集成了log4net,log.txt为日志...
IbatisNet从入门到精通,根据源码详细介绍,保证对IbatisNet能有个深入的了解。自己写的。呵呵
IBatisNet.DataMapper 1.6.1.0之简单三层 首先介绍Solution的架构,一共分四个项目: Web :前台应用; BLL :业务处理层,如果嫌麻烦,可以再进一步抽象出来,然后将代码放置Web层的aspx.cs里面; Model :这个...
iBATISNet Database Layer!这个框架将让你能够更好的在dotnet应用中设计和实现实体层。这个框架有两个主要的组成部分,一个是SQL Maps,另一个是Data Access Objects。下面是一个简单的iBATISNet应用架构。 项目中...
Ibatisnet介绍和使用
IBatisNet 框架 项目实例
理解ibatisnet机制,从入门到会只要几天时间,ORM模式很大程度上改善了代码的质量,效率更高,代码更少。
本示例是用DWZ+ibatisnet实现的一个报表系统。数据库为sql 2008 R2版本
列举了IBatisNet的用法实例,简单的入门开始
基于C#的iBatisNet详细使用案例说明。
IBatisNet源代码 反编译出来的。。编译通过,最新版本。
IBatisNet在.NET中的使用总结
C#开发 MonoRail+IBatisNet +Velocity+vs2010的项目实例,初学者配置起来比较繁琐,配置好使用起来发现IBatisNet 还是很强大的!
通过研究IBatisNet源码主要是操作守护静态类来实现多源数据库的连接操作 IBatisNet同时连接多个数据库(orcl、sqllite、sqlserver) 并附带如何保存图片到ORACLE数据库
对于IBatisNet的新手还是很有帮助的
IBatisNet+Castle项目实例