ibatis中isEquals、isNotEmpty的用法
阿新 • • 發佈:2019-05-15
align 數據 sql sco temp hit bbb pup 實例
一:isEquals用於動態拼接sql
如下實例:
如果status的狀態為0,則更新attribute1;狀態為1,則更新attribute2;
狀態為2,則更新attribute3。
<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 <select id="topup.querySuccessCount" parameterClass="java.util.HashMap"> 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 id="insertWtly" parameterClass="sasbxxb" > insert into <isEqual compareValue="1" prepend="" property="shengfen"> SBXX_SBBH_MUCHREG </isEqual> ( MUCHID, REG_NAME, COUNTRY, REG_DISTRICT,
也可以下面這樣用
ibatis中isEquals、isNotEmpty的用法