欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mybatis foreach遍歷LIST讀到數(shù)據(jù)為null的問題

 更新時間:2022年02月08日 10:29:42   作者:xshxxm  
這篇文章主要介紹了mybatis foreach遍歷LIST讀到數(shù)據(jù)為null的問題,具有很好的參考價值,希望對大家有所幫助。

foreach遍歷LIST讀到數(shù)據(jù)為null

當(dāng)我們在使用mybatis的時候,就避免不了批量更新,或者批量查詢使用數(shù)組或者list,就避免不了使用foreach遍歷,當(dāng)我們在遍歷的時候,數(shù)據(jù)遍歷不出來,取出的值是null

解決方案

如下:只需要修改為下標取值

foreach 遍歷list中的坑

將jdbc改寫為mybatis時,傳入的條件為list使用到的標簽是<where> 、<choose>、<when>、<if>、<foreach>因為判斷l(xiāng)ist集合時判斷條件不全,導(dǎo)致sql執(zhí)行錯誤

下面是正確的判斷條件

<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>

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論