溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么解析iBATIS.NET多數(shù)據(jù)庫支持

發(fā)布時間:2021-10-28 10:18:41 來源:億速云 閱讀:107 作者:柒染 欄目:編程語言

這篇文章給大家介紹怎么解析iBATIS.NET多數(shù)據(jù)庫支持,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

談到iBATIS.NET多數(shù)據(jù)庫支持我們首先來看看它本身的幫助文檔,在iBATIS.NET的幫助文檔中有介紹多數(shù)據(jù)庫支持,但是沒有寫全代碼,后來查看其源碼,并結合幫助文檔,找到了解決方法,其實道理就是另行實現(xiàn)一個Mapper.

iBATIS.NET多數(shù)據(jù)庫支持實例如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),就是根據(jù)另一個AnthorMap.config文件來生成SqlMapper。

AnthorMap.config和默認的SqlMap.config一樣,只是根據(jù)你的數(shù)據(jù)不同設置不同而已,測試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多數(shù)據(jù)庫支持之使用AntherMapper來創(chuàng)建ISqlMapper了。如下:

public IList﹤Weather﹥GetWeather()      {           ISqlMapper map = AnthorMapper.Instance();                return map.QueryForList﹤Weather>("Weather.Select", null);      }

那么iBATIS.NET多數(shù)據(jù)庫支持就介紹到這里。

關于怎么解析iBATIS.NET多數(shù)據(jù)庫支持就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI