[quote]在工作中遇到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>
[color=red][b]<when test="sameNameList != null and sameNameList.size > 0">[/b][/color]
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
[/quote]
[url]https://blog.csdn.net/cloudzpc/article/details/78254479[/url]
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>
[color=red][b]<when test="sameNameList != null and sameNameList.size > 0">[/b][/color]
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
[/quote]
[url]https://blog.csdn.net/cloudzpc/article/details/78254479[/url]