iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >mybatisforeach遍历LIST读到数据为null的问题
  • 194
分享到

mybatisforeach遍历LIST读到数据为null的问题

2024-04-02 19:04:59 194人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

目录foreach遍历LIST读到数据为null解决方案foreach 遍历list中的坑下面是正确的判断条件foreach遍历LIST读到数据为null 当我们在使用mybatis

foreach遍历LIST读到数据为null

当我们在使用mybatis的时候,就避免不了批量更新,或者批量查询使用数组或者list,就避免不了使用foreach遍历,当我们在遍历的时候,数据遍历不出来,取出的值是null

解决方案

如下:只需要修改为下标取值

foreach 遍历list中的坑

将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文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作