第一范文网 - 专业文章范例文档资料分享平台

IBatis教程 

来源:用户分享 时间:2025/5/19 5:37:48 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

日志方法二:

日志方法三:

使用其它方式的日志记录方式,只需要声明市适当的ogFactoryAdapter即可。在iBATISDataMapper框架中使用ApacheLog4Net记录日志的配置如下所示:

或者

Log4NetLoggerFA提供了下表的属性参数设置:

配置类型inline

说明

log4net节点使用当前这个应用程序配置文件(app.config/web.config或其它名称的配置文件)文件中的log4net节点。

filefile-watch

(同时需要提供configFile参数)-log4net使用在configFile参数中指定的文件处理日志。

(同时需要提供configFile参数)-log4net使用在configFile参数中指定的文件处理日志,如果configFile参数中指定的文件内容有变化,log4net会自动根据新的配置进行重新设置。

externaliBATIS不对log4net进行配置.

6.6.12.1举例:

1.用于Consoleout输出日志的最简单配置:

为了在我们的应用程序中使用Log4Net,需要提供对Log4Net的配置信息。可以在我们的构件中增加一个配置文件,并在配置文件中含有元素来完成。配置文件的命名按照我们自己的构件命名方式命名,但扩展名必须是“.config”,并和构件文件放在同一个文件夹下。下面的例子展示了对Log4Net的基本配置段(文件名称为IBatisNet.DataMapper.Test.dll.Config),它的含义是创建一个log4net.txt文件,并把log4net的debug信息保存在这个文档中。在log4net没有调试数据的时可以查看这个文件。下面是一个完整的配置代码(文件名为:IBatisNet.DataMapper.Test.dll.Config)

IBatisNet.DataMapper.Configuration.Statements.DefaultPreparedCommand项表明把DataMapper中生成的数据库操作语句、参数、参数值也记录在日志中,这有利于对程序进行调试。

下面是一段对数据库操作语句的日志记录样本:

2005-06-0801:39:33[3872]DEBUGIBatisNet.DataMapper.Commands.DefaultPreparedCommand-StatementId:[User.Update]PreparedStatement:[UPDATE[User]SET[DateLastUpdated]=NOW()WHERE[UserId]=?]2005-06-0801:39:43[3872]DEBUGIBatisNet.DataMapper.Commands.DefaultPreparedCommand-StatementId:[User.Update]Parameters:[param0=[UserId,1]]

2005-06-0801:39:53[3872]DEBUGIBatisNet.DataMapper.Commands.DefaultPreparedCommand-StatementId:[User.Update]Types:[param0=[String,System.Int32]]

还可以把通过使用正则表达式对日志字符串进行过滤,把不同的操作语句日志存放到不同的文件中。如下例所示:

Cache日志样本:

2005-06-0801:38:34,403[3648]DEBUGIBatisNet.DataMapper.Configuration.Cache.CacheModel-FlushcacheModelnamedAccount.account-cacheforstatement'UpdateAccountViaParameterMap'

DataMapper数据源连接会话日志样本:

2005-06-0801:39:42,660[3872]DEBUGIBatisNet.DataMapper.SqlMapSession[]-OpenConnection\

to\SQLServer7.0/2000,providerV1.0.5000.0inframework.NETV1.1\

2005-06-0801:39:42,660[3872]DEBUGIBatisNet.DataMapper.Commands.DefaultPreparedCommand[]-PreparedStatement:[select*fromOrderswhereOrder_ID=@param0]

2005-06-0801:39:42,660[3872]DEBUGIBatisNet.DataMapper.Commands.DefaultPreparedCommand[]-Parameters:[@param0=[value,1]]

2005-06-0801:39:42,660[3872]DEBUGIBatisNet.DataMapper.Commands.DefaultPreparedCommand[]-Types:[@param0=[Int32,System.Int32]]

2005-06-0801:39:42,676[3872]DEBUGIBatisNet.DataMapper.SqlMapSession[]-CloseConnection\to

\SQLServer7.0/2000,providerV1.0.5000.0inframework.NETV1.1\

LazyLoadList运行日志样本:

2005-06-0801:39:42,316[3872]DEBUGIBatisNet.DataMapper.LazyLoadList[]-Proxyfyingcalltoget_Count

2005-06-0801:39:42,316[3872]DEBUGIBatisNet.DataMapper.LazyLoadList[]-Proxyfyingcall,querystatementGetLineItemsForOrder

2005-06-0801:39:42,316[3872]DEBUGIBatisNet.DataMapper.SqlMapSession[]-OpenConnection\to

\SQLServer7.0/2000,providerV1.0.5000.0inframework.NETV1.1\

2005-06-0801:39:42,316[3872]DEBUGIBatisNet.DataMapper.Commands.DefaultPreparedCommand[]-PreparedStatement:[selectLineItem_IDasId,LineItem_CodeasCode,LineItem_QuantityasQuantity,LineItem_PriceasPricefromLineItemswhereOrder_ID=@param0]

2005-06-0801:39:42,316[3872]DEBUGIBatisNet.DataMapper.Commands.DefaultPreparedCommand[]-Parameters:[@param0=[value,1]]

2005-06-0801:39:42,316[3872]DEBUGIBatisNet.DataMapper.Commands.DefaultPreparedCommand[]-Types:[@param0=[Int32,System.Int32]]

2005-06-0801:39:42,316[3872]DEBUGIBatisNet.DataMapper.SqlMapSession[]-CloseConnection\to

\SQLServer7.0/2000,providerV1.0.5000.0inframework.NETV1.1\2005-06-0801:39:42,316[3872]DEBUGIBatisNet.DataMapper.LazyLoadList[]-Endofproxyfiedcalltoget_Count

七、数据映射(DataMap)7.1数据映射定义文件

下面是一个简单的数据映射定义文件:

(Order_Id,LineItem_LineNum,Item_Id,LineItem_Quantity,LineItem_UnitPrice)VALUES

(#Order.Id#,#LineNumber#,#Item.Id#,#Quantity#,#Item.ListPrice#)

对于上面这段指令映射定义,映射机制从LineItem实例中提取所需的属性值,然后和数据操作指令合并成可执行的正确语句,有数据提供者在数据库中运行。通过向映射框架API直接传递对象实例,就可以完成自动匹配。调用例句:

C#

Mapper.Instance().Insert(\下面给出一个复杂些的数据映射例子:

xmlns:xsi=\http://www.w3.org/2001/XMLSchema-instance\>

搜索更多关于: IBatis教程  的文档
IBatis教程 .doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c1ob9s1oo6h6et871e27e_6.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top