mybatis判斷l(xiāng)ist不為空/大小的問題
更新時間:2022年01月21日 14:27:00 作者:sayyy
這篇文章主要介紹了mybatis判斷l(xiāng)ist不為空/大小的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
mybatis判斷l(xiāng)ist不為空
?? ?<if test="status != null and status.size()>0" >
? ? ? and s.orderstatus in?
? ? ? <foreach collection="status" item="listItem" open="(" close=")" separator="," >
? ? ? ? #{listItem}
? ? ? </foreach>
? ? </if> ??建議對特殊字符進行處理
?? ?<if test="status != null and status.size() > 0" >
? ? ? and s.orderstatus in?
? ? ? <foreach collection="status" item="listItem" open="(" close=")" separator="," >
? ? ? ? #{listItem}
? ? ? </foreach>
? ? </if> ??mybatis判斷兩個集合是否為空
在工作中遇到mybatis中判斷兩個集合是否為空,不為空的話遍歷;都為空執(zhí)行 1=0 or 1=0,則查詢出來空集合
select login,name,email from users u where
<choose>
? ? <when test="sameEmailList != null and sameEmailList.size > 0 ">
? ? ? ? email in <foreach collection="sameEmailList" item="email" open="(" separator="," close=")">
? ? ? ? #{email, jdbcType=VARCHAR}
? ? ? ? </foreach>
? ? </when>
? ? <otherwise>
? ? ? ? 1 = 0
? ? </otherwise>
</choose>
<choose>
? ? <when test="sameNameList != null and sameNameList.size > 0">
? ? ? ? or name in <foreach collection="sameNameList" item="name" open="(" separator="," close=")">
? ? ? ? #{name, jdbcType=VARCHAR}
? ? </foreach>
? ? </when>
? ? <otherwise>
? ? ? ? or 1 = 0
? ? </otherwise>
</choose>
ORDER by name, email ASC以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

