zoukankan      html  css  js  c++  java
  • mybatis 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>

  • 相关阅读:
    斐波那契(通项公式)
    数论--欧几里得定理(求最大公约数)
    5790 素数序数(筛素数版)
    数论--筛法求素数
    2491 玉蟾宫
    闭包详解
    ASP.NET 页生命周期概述1
    IIS 7.0 的 ASP.NET 应用程序生命周期概述
    IIS 5.0 和 6.0 的 ASP.NET 应用程序生命周期概述
    WeUI logo专为微信设计的 UI 库 WeUI
  • 原文地址:https://www.cnblogs.com/wangjinyu/p/9959305.html
Copyright © 2011-2022 走看看