首页 > 技术文章 > mybatis动态sql foreach的用法

feifeicui 2018-05-06 15:27 原文

    <select id="findUserByIds" parameterType="com.pojo.QueryVo" resultType="com.pojo.User">
        SELECT * from USER
      <where>
          <if test="ids !=null">
              <!--
              foreach:循环传入的集合参数
              collection:传入的集合的变量名称
              item:每次循环将循环出的数据放入这个变量中
              open循环开始拼接的字符串
              separator:循环中拼接的分隔符
              -->
              <foreach collection="ids" item="id" open="id in(" close=")" separator=",">
              #{id}
              </foreach>
          </if>
      </where>
    </select>

 

推荐阅读