mybatis判断list不为空/大小的问题
作者:sayyy
这篇文章主要介绍了mybatis判断list不为空/大小的问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
mybatis判断list不为空
<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中判断两个集合是否为空,不为空的话遍历;都为空执行 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以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
