Ibatis动态查询例子(#和$以及iterate等的用法)

本文介绍了Ibatis动态查询的使用,包括#、$的区别以及iterate标签的运用。通过示例展示了如何根据不同的查询条件构造灵活的SQL语句,实现更高效的数据筛选和排序。同时,文章还提到了数据访问层和服务层的代码实现,以及如何处理分页查询。
摘要由CSDN通过智能技术生成

最近做了很多动态的查询,尤其是排序,以及一些状态字段,所以就做了一个总的动态查询,以不变应万变,呵呵

 

ibatis 里面的sql代码:

Xml代码 复制代码
  1. <select id="getTopics" resultClass="topic" parameterClass="map">  
  2.         <![CDATA[  
  3.                 select * from p_Topic   
  4.         ]]>  
  5.     <dynamic prepend=" WHERE ">  
  6.         <isPropertyAvailable property="authorId">  
  7.             <isNotNull property="authorId" prepend=" and ">  
  8.                 authorId=#authorId#    
  9.                </isNotNull>  
  10.         </isPropertyAvailable>  
  11.         <isPropertyAvailable property="marketId">  
  12.             <isNotNull property="marketId" prepend=" and ">  
  13.                 marketId=#marketId#    
  14.                </isNotNull>  
  15.         </isPropertyAvailable>  
  16.   
  17.         <isPropertyAvailable property="isDelete">  
  18.             <isNotNull property="isDelete" prepend=" and ">  
  19.                 isDelete=#isDelete#    
  20.                </isNotNull>  
  21.         </isPropertyAvailable>  
  22.   
  23.         <isPropertyAvailable property="isBest">  
  24.             <isNotNull property="isBest" prepend=" and ">  
  25.                 isBest=#isBest#   
  26.             </isNotNull>  
  27.         </isPropertyAvailable>  
  28.   
  29.         <isPropertyAvailable property="statusStr">  
  30.             <isNotNull property="statusStr" prepend=" and ">  
  31.                 $statusStr$   
  32.             </isNotNull>  
  33.         </isPropertyAvailable>  
  34.         <isPropertyAvailable property="marketIdList">  
  35.             <isNotNull property="marketIdList" prepend=" and marketId in ">  
  36.                 <iterate property="marketIdList" conjunction="," close=")" open="(">  
  37.                     #marketIdList[]#   
  38.                 </iterate>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值