一:isEquals用于动态拼接sql
如下实例:
如果status的状态为0,则更新attribute1;状态为1,则更新attribute2;
状态为2,则更新attribute3。
1 2 3 4 5 6 7 8 9 10 |
<update id="topup.doEffect" parameterClass="java.util.HashMap"> 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> |
二:isNotEmpty
如下实例:
查询cis_customer这张表,如果属性aaa不为空,则将条件aaa=#aaa#拼接;
如果bbb不为空,则将条件bbb=#bbb#拼接;如果属性ccc不为空,则将条件ccc=#ccc#拼接;
1 2 3 4 5 6 7 8 9 10 11 12 |
<select id="topup.querySuccessCount" parameterClass="java.util.HashMap"> select id,name from cis_customer where 1=1 <isNotEmpty property="aaa" prepend="and"> aaa=#aaa# </isNotEmpty > <isNotEmpty property="bbb" prepend="and"> bbb=#bbb# </isNotEmpty > <isNotEmpty property="ccc" prepend="and"> ccc=#ccc# </isNotEmpty > </select> |