ibatis 中isNull, isNotNull与isEmpty, isNotEmpty区别

在iBATIS中isNull用于判断参数是否为Null,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>

当之传入参数 cusWebForm 而不传入 cusWebAgent 时,产生的SQL语句为:
select count(cus_id) from cus_customer_tbl    WHERE      ( CUS_CUSTOMER_TBL.CUS_WEB_FROM LIKE '%baidu%')

而当XML代码用<isNotNull > 配置时(注意他们的区别),
	 <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>

同样 ,当之传入参数 cusWebForm 而不传入 cusWebAgent 时,产生的SQL语句为:
select count(cus_id) from cus_customer_tbl     WHERE     ( CUS_CUSTOMER_TBL.CUS_WEB_FROM LIKE '%baidu%')      AND        (CUS_CUSTOMER_TBL.CUS_WEB_AGENT LIKE '%%')

从Sql 语句就能看出他们的区别。。。。。

你可能感兴趣的:(ibatis)