ibatis中isEquals、isNotEmpty的用法

一:isEquals用于动态拼接sql

如下实例:

如果status的状态为0,则更新attribute1;状态为1,则更新attribute2;

状态为2,则更新attribute3。

ibatis中isEquals、isNotEmpty的用法
<update   >
update  cis_customer  set  code_id  = #codeId# ,
<isEqual property="status" compareValue="0" prepend=",">  
            attribute1=#attribute1#</isEqual>  
        <isEqual property="status" compareValue="1" prepend=",">  
            attribute2=#attribute2#</isEqual>  
        <isEqual property="status" compareValue="2" prepend=",">  
            attribute3=#attribute3#</isEqual>
where  id = #id#
</update>  
ibatis中isEquals、isNotEmpty的用法

二:isNotEmpty

如下实例:

查询cis_customer这张表,如果属性aaa不为空,则将条件aaa=#aaa#拼接;

如果bbb不为空,则将条件bbb=#bbb#拼接;如果属性ccc不为空,则将条件ccc=#ccc#拼接;

ibatis中isEquals、isNotEmpty的用法
 1 <select  >
 2      select id,name from cis_customer where 1=1
 3      <isNotEmpty  property="aaa"  prepend="and">  
 4                  aaa=#aaa#
 5   </isNotEmpty  >  
 6   <isNotEmpty  property="bbb"  prepend="and">  
 7                  bbb=#bbb#
 8    </isNotEmpty  >  
 9    <isNotEmpty  property="ccc" prepend="and">  
10                 ccc=#ccc#
11   </isNotEmpty  >
12   </select>  



也可以下面这样用
<!-- 插入一条问题来源数据 -->
<insert >
insert into
<isEqual compareValue="1" prepend=""
property="shengfen">
SBXX_SBBH_MUCHREG
</isEqual>
( MUCHID,
REG_NAME,
COUNTRY,
REG_DISTRICT,