iBATIS模糊查询的实现实例浅析

开发 后端
iBATIS模糊查询的实现实例向你介绍了iBATIS模糊查询是如何实现的,以及具体的源码实现。

iBATIS模糊查询的实现是如何的呢?让我们先看看例子,仿照Java的Spring+Ibatis+Struct用Castle+IBatisNet+Asp.net的开发框架的DAO的基类:BaseSqlMapDao内定义了一个内部类来辅助模糊查询。内部类代码如下:

  1. protected internal  class KeyWordSearch   
  2.   {  
  3.    private IList keywordList = new ArrayList();  
  4.  
  5.    public KeyWordSearch(String keywords)   
  6.    {  
  7.     StringTokenizer splitter = new StringTokenizer(keywords, " "false);  
  8.     string token = null;  
  9.  
  10.     IEnumerator enumerator = splitter.GetEnumerator();  
  11.  
  12.     while (enumerator.MoveNext())   
  13.     {  
  14.      token = (string)enumerator.Current;  
  15.      keywordList.Add("%" + token + "%");  
  16.     }  
  17.    }  
  18.  
  19.    public IList KeywordList   
  20.    {  
  21.     get  
  22.     {  
  23.      return keywordList;  
  24.     }  
  25.    }  
  26.   } 

在需要使用iBATIS模糊查询的数据访问类的方法中使用方法如下:

例如数据访问类PersonInfoDao继承自BaseSqlMapDao,方法

  1. /// <summary>  
  2.   /// 检索求职者信息,根据关键字检索  
  3.   /// </summary>  
  4.   public IList SearchPersonInfoList(string keywords)  
  5.   {  
  6.    object parameterObject = new KeyWordSearch(keywords);  
  7.    return this.ExecuteQueryForList("SearchPersonList", parameterObject);  
  8.   }  
  9.  
  10. <select id="SearchPersonList" resultMap="PersonResult">  
  11.    select UserId,UserName,Sex,Birthday,Mobile,HomeTel,EMail,LivingArea,  
  12.             RegisteredLocus,GraduateSchool,MajorSpecialty,JobExperience,MonthlyPay,  
  13.             Special,Resume,city.code,city.name,person.NationId,Nation.NationName,  
  14.             person.JobId,job.jobName,person.degreeId,degree.DegreeName  
  15.             from Career_PersonInfo person ,Career_Nation nation,Career_Job job,Career_City city,Career_Degree degree  
  16.             where person.CityCode = city.code and person.NationId = nation.NationId and person.jobid = job.jobId  
  17.             and person.degreeId = degree.degreeId  
  18.             <dynamic prepend="and">   
  19.     <iterate property="KeywordList" open="" close="" conjunction="OR">  
  20.      lower(job.jobName) like #KeywordList[]#   
  21.     </iterate>  
  22.    </dynamic>  
  23.   </select> 

iBATIS模糊查询的情况就向你介绍到这里,希望通过例子能够使你对iBATIS模糊查询的是实现有所帮助。

【编辑推荐】

  1. iBATIS映射文件基础浅谈
  2. iBATIS ParameterMap配置实例浅析
  3. iBATIS ResultMap基础浅析
  4. iBATIS CacheModel使用浅析
  5. iBATIS分页实例中ObjectDataSource的应用浅析
责任编辑:仲衡 来源: cnblogs
相关推荐

2009-07-22 13:04:41

iBATIS动态查询

2009-08-27 18:09:49

C#接口的实现

2009-07-22 09:44:05

iBATIS Para

2009-07-24 16:59:57

iBatis模糊查询

2009-08-14 09:50:46

C#复制构造函数

2009-09-04 17:20:23

C# DES加密解密

2009-07-22 11:11:39

iBATIS分页实例ObjectDataS

2009-07-15 13:11:25

ibatis动态查询

2009-07-20 10:06:07

iBATIS.net查询方式

2009-07-20 17:01:11

Struts2.0+i

2009-07-17 17:45:56

iBATIS Spri

2009-08-31 12:31:45

C#创建文件夹

2009-07-17 10:20:24

iBATIS实例

2009-09-14 17:10:57

LINQ模糊查询

2009-07-21 11:12:00

iBATIS配置

2009-09-14 18:19:49

LINQ模糊查询

2009-07-17 10:59:59

iBATIS接口

2010-10-29 16:41:12

Oracle模糊查询

2009-07-15 17:19:31

iBATIS Ecli

2009-07-22 10:03:11

iBATIS Resu
点赞
收藏

51CTO技术栈公众号