Python 官方文档:入门教程 => 点击学习
目录foreach遍历LIST读到数据为null解决方案foreach 遍历list中的坑下面是正确的判断条件foreach遍历LIST读到数据为null 当我们在使用mybatis
当我们在使用mybatis的时候,就避免不了批量更新,或者批量查询使用数组或者list,就避免不了使用foreach遍历,当我们在遍历的时候,数据遍历不出来,取出的值是null
如下:只需要修改为下标取值
将jdbc改写为mybatis时,传入的条件为list使用到的标签是<where> 、<choose>、<when>、<if>、<foreach>因为判断list集合时判断条件不全,导致sql执行错误
<where>
<choose>
<when test="unitList != null and ! unitList.isEmpty() and unitList.size() > 0">
(tab2.id IN
<foreach collection="unitList" item="item" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
AND tab1.`status` = #{deviceStatus})
<if test="zoonList != null and ! zoonList.isEmpty() and zoonList.size() > 0">
OR (tab2.leaderId IN
<foreach collection="zoonList" item="item" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
AND tab1.`status` = #{deviceStatus})
</if>
</when>
<when test="zoonList != null and ! zoonList.isEmpty() and zoonList.size() > 0">
tab2.leaderId IN
<foreach collection="zoonList" item="item" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
AND tab1.`status` = #{deviceStatus}
</when>
</choose>
</where>
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: mybatisforeach遍历LIST读到数据为null的问题
本文链接: https://www.lsjlt.com/news/138390.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0