ibatis 模糊查询语句总结

在涉及到ibatis的条件查询的时候,有下面几种查询方式:
isNull, isNotNull与isEmpty, isNotEmpty
那么这几种查询判定条件有什么区别呢?

首先比较 isNull 和 isNotNull的不同:
不用多说这两个很明显一个是判断参数是否为空(isNull), 另一个则相反(isNotNull)

isEmpty 是判断参数是否为NULL或者为空,满足其中一个条件则为true
isNotEmpty 相反, 当参数既不为空也不为NULL的时候为true

<select id="getCustomerRegNum" resultClass="int" parameterClass="QueryCustomerCondition"> 
          select count(cus_id) from cus_customer_tbl  
          <dynamic prepend="WHERE"> 
            <isNotEmpty prepend="AND" property="cusWebFrom"> 
                ( CUS_CUSTOMER_TBL.CUS_WEB_FROM LIKE '%$cusWebFrom$%') 
            </isNotEmpty> 
            <isNotEmpty prepend="AND" property="cusWebAgent"> 
                ( CUS_CUSTOMER_TBL.CUS_WEB_AGENT LIKE '%$cusWebAgent$%') 
            </isNotEmpty> 
          </dynamic> 
</select>



    <select id="getCustomerRegNum" resultClass="int" parameterClass="QueryCustomerCondition"> 
              select count(cus_id) from cus_customer_tbl  
              <dynamic prepend="WHERE"> 
                <isNotNull prepend="AND" property="cusWebFrom"> 
                    ( CUS_CUSTOMER_TBL.CUS_WEB_FROM LIKE '%$cusWebFrom$%') 
                </isNotNull> 
                <isNotNull prepend="AND" property="cusWebAgent"> 
                    ( CUS_CUSTOMER_TBL.CUS_WEB_AGENT LIKE '%$cusWebAgent$%') 
                </isNotNull> 
              </dynamic> 
       </select> 

你可能感兴趣的:(ibatis,isnotnull,isNull,isnotempty)