mybatis中判断两个集合是否为空

[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]
MyBatis的if test判断,可以使用两种方式来判断一个List集合是否为空。一种是通过判断List对象是否为null,并且判断List的size是否为0来确定。示例代码如下: ```xml <if test="list!=null and list.size()!=0"></if> ``` 另一种方式是通过判断List对象是否为null,并且直接判断List对象在标签内部是否为空来确定。示例代码如下: ```xml <if test="list!=null"> <!-- 在这里写逻辑判断 --> </if> ``` 所以,根据你提供的引用内容,如果需要在MyBatis的mapper.xml判断一个list集合是否为空,可以使用上述的两种方式之一来实现。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Mybatis if test 判断 list不为 null 并且判断集合大小不为0](https://blog.csdn.net/zl18603543572/article/details/125006233)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [mybatis if test判断 list不为](https://blog.csdn.net/weixin_44476553/article/details/114333172)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值