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
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
JAVA基于數(shù)組實現(xiàn)的商品信息查詢功能示例
這篇文章主要介紹了JAVA基于數(shù)組實現(xiàn)的商品信息查詢功能,結合實例形式詳細分析了java使用數(shù)組存儲數(shù)據(jù)實現(xiàn)的商品信息查詢功能相關操作技巧,需要的朋友可以參考下2019-11-11Flask接口如何返回JSON格式數(shù)據(jù)自動解析
這篇文章主要介紹了Flask接口如何返回JSON格式數(shù)據(jù)自動解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-11-11