怎么解析iBATIS.NET多数据库支持
发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,这篇文章给大家介绍怎么解析iBATIS.NET多数据库支持,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。谈到iBATIS.NET多数据库支持我们首先来看看它本身的帮助文档,在iB
千家信息网最后更新 2024年09月22日怎么解析iBATIS.NET多数据库支持
这篇文章给大家介绍怎么解析iBATIS.NET多数据库支持,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
谈到iBATIS.NET多数据库支持我们首先来看看它本身的帮助文档,在iBATIS.NET的帮助文档中有介绍多数据库支持,但是没有写全代码,后来查看其源码,并结合帮助文档,找到了解决方法,其实道理就是另行实现一个Mapper.
iBATIS.NET多数据库支持实例如AnthorMapper:
Apache Notice#region Apache Notice #endregion using IBatisNet.Common.Utilities; using IBatisNet.DataMapper; using IBatisNet.DataMapper.Configuration; namespace IBatisNet.DataMapper { /**//// ﹤summary﹥ /// A singleton class to access the default SqlMapper defined by the SqlMap.Config /// ﹤/summary﹥ public sealed class AnthorMapper { Fields#region Fields private static volatile ISqlMapper _mapper = null; #endregion /**//// ﹤summary﹥ /// /// ﹤/summary﹥ /// ﹤param name="obj">﹤/param﹥ public static void Configure (object obj) { _mapper = null; } /**//// ﹤summary﹥ /// Init the 'default' SqlMapper defined by the SqlMap.Config file. /// ﹤/summary﹥ public static void InitMapper() { ConfigureHandler handler = new ConfigureHandler (Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); _mapper = builder.ConfigureAndWatch ("AnthorMap.config",handler); } /**//// ﹤summary﹥ /// Get the instance of the SqlMapper defined by the SqlMap.Config file. /// ﹤/summary﹥ /// ﹤returns>A SqlMapper initalized via the SqlMap.Config file.﹤/returns﹥ public static ISqlMapper Instance() { if (_mapper == null) { lock (typeof (SqlMapper)) { if (_mapper == null) // double-check { InitMapper(); } } } return _mapper; } /**//// ﹤summary﹥ /// Get the instance of the SqlMapper defined by the SqlMap.Config file. (Convenience form of Instance method.) /// ﹤/summary﹥ /// ﹤returns>A SqlMapper initalized via the SqlMap.Config file.﹤/returns﹥ public static ISqlMapper Get() { return Instance(); } } }
以上代码只是修改了iBATIS.NET中的Mapper的代码,将_mapper = builder.ConfigureAndWatch (handler);修改为_mapper = builder.ConfigureAndWatch ("AnthorMap.config",handler),就是根据另一个AnthorMap.config文件来生成SqlMapper。
AnthorMap.config和默认的SqlMap.config一样,只是根据你的数据不同设置不同而已,测试AnthorMap.config如下如下:
﹤?xml version="1.0" encoding="utf-8"?﹥ ﹤sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"﹥ ﹤settings﹥ ﹤setting useStatementNamespaces="true"/﹥ ﹤/settings﹥ ﹤providers resource="ServerConfig/providers.config"/﹥ ﹤!-- Database connection information --﹥ ﹤database﹥ ﹤provider name="sqlServer2.0"/﹥ ﹤dataSource name="CrmSystem" connectionString="server=.;database=TestDB;uid=sa;pwd="/﹥ ﹤/database﹥ ﹤sqlMaps﹥ ﹤sqlMap embedded="Test.Domain.Weather.xml,Test.Domain" /﹥ ﹤/sqlMaps﹥ ﹤/sqlMapConfig﹥
iBATIS.NET多数据库支持之使用AntherMapper来创建ISqlMapper了。如下:
public IList﹤Weather﹥GetWeather() { ISqlMapper map = AnthorMapper.Instance(); return map.QueryForList﹤Weather>("Weather.Select", null); }
那么iBATIS.NET多数据库支持就介绍到这里。
关于怎么解析iBATIS.NET多数据库支持就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
数据
数据库
支持
帮助
代码
文档
不同
内容
只是
就是
更多
不错
兴趣
实例
小伙
小伙伴
文件
文章
方法
有介绍
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全第41条
杭州erp软件开发贵吗
存储服务器实现文件共享
阿里巴巴软件开发面试
中专计算机网络技术有前景
腾讯会议服务器链接异常
彩虹 版本数据库管理工具
公安网络安全执法工作培训班
无法还原数据库
巅峰战舰服务器维护
公安网络安全训诫书模板
潍坊百盛网络技术有限公司
华侨大学数据库系统原理答案
服务器有自动化系统吗
互联网家装科技化
饥荒服务器存档备份
基于windows的数据库
联想服务器读不到u盘
sql数据库采用强事务
扫描数据库安全漏洞
软件开发和软件测试的关系
大连埃森哲网络安全管理
阿里云服务器经典网络怎么设置
苏州系统软件开发哪家正规
上海led视频服务器厂家
hsqldb数据库忘记密码
银行网络技术人员演讲稿
软件开发人员的基本工作内容
数据库表格中设置默认值
网络安全报案与配合调查