mybatis判斷l(xiāng)ist不為空/大小的問(wèn)題
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> ??建議對(duì)特殊字符進(jìn)行處理
?? ?<if test="status != null and status.size() > 0" >
? ? ? and s.orderstatus in?
? ? ? <foreach collection="status" item="listItem" open="(" close=")" separator="," >
? ? ? ? #{listItem}
? ? ? </foreach>
? ? </if> ??mybatis判斷兩個(gè)集合是否為空
在工作中遇到mybatis中判斷兩個(gè)集合是否為空,不為空的話(huà)遍歷;都為空?qǐng)?zhí)行 1=0 or 1=0,則查詢(xún)出來(lái)空集合
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以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
java設(shè)計(jì)模式之觀察者模式簡(jiǎn)單解讀
這篇文章主要介紹了java設(shè)計(jì)模式之觀察者模式簡(jiǎn)單解讀,觀察者模式是在對(duì)象之間定義了一對(duì)多的依賴(lài),這樣一來(lái),當(dāng)一個(gè)對(duì)象改變狀態(tài),依賴(lài)它的對(duì)象會(huì)收到通知并自動(dòng)更新,需要的朋友可以參考下2023-10-10
JAVA基于數(shù)組實(shí)現(xiàn)的商品信息查詢(xún)功能示例
這篇文章主要介紹了JAVA基于數(shù)組實(shí)現(xiàn)的商品信息查詢(xún)功能,結(jié)合實(shí)例形式詳細(xì)分析了java使用數(shù)組存儲(chǔ)數(shù)據(jù)實(shí)現(xiàn)的商品信息查詢(xún)功能相關(guān)操作技巧,需要的朋友可以參考下2019-11-11
Flask接口如何返回JSON格式數(shù)據(jù)自動(dòng)解析
這篇文章主要介紹了Flask接口如何返回JSON格式數(shù)據(jù)自動(dòng)解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11
鄰接表無(wú)向圖的Java語(yǔ)言實(shí)現(xiàn)完整源碼
這篇文章主要介紹了鄰接表無(wú)向圖的Java語(yǔ)言實(shí)現(xiàn)完整源碼,具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-12-12

