怎么解析iBATIS.NET多数据库支持

发布时间:2021-10-28 10:18:41 作者:柒染
来源:亿速云 阅读:102

这篇文章给大家介绍怎么解析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多数据库支持就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. DNSDUN免费支持全球解析
  2. 支持多编辑风格和引用通用查询

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ibatis.net

上一篇:怎么用ASP.NET MVC源代码寻找解决方案

下一篇:Mysql数据分组排名实现的示例分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》