mybatis判斷l(xiāng)ist不為空/大小的問(wèn)題
更新時(shí)間:2022年01月21日 14:27:00 作者:sayyy
這篇文章主要介紹了mybatis判斷l(xiāng)ist不為空/大小的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
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è)集合是否為空,不為空的話遍歷;都為空?qǐng)?zhí)行 1=0 or 1=0,則查詢出來(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),當(dāng)一個(gè)對(duì)象改變狀態(tài),依賴它的對(duì)象會(huì)收到通知并自動(dòng)更新,需要的朋友可以參考下2023-10-10JAVA基于數(shù)組實(shí)現(xiàn)的商品信息查詢功能示例
這篇文章主要介紹了JAVA基于數(shù)組實(shí)現(xiàn)的商品信息查詢功能,結(jié)合實(shí)例形式詳細(xì)分析了java使用數(shù)組存儲(chǔ)數(shù)據(jù)實(shí)現(xiàn)的商品信息查詢功能相關(guān)操作技巧,需要的朋友可以參考下2019-11-11Flask接口如何返回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