<select id="xxx" resultType="java.lang.String">
SELECT *
FROM testTable t
<where>
1=1
<!-- 加choose:防止外部传入空数据,获取了全量数据 -->
<choose>
<when test="ids!=null and ids.size()>0">
AND (t.ID IN
<foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
<!-- 在遍历的过程中,每N个数据需要添加一个IN,并采用or连接 -->
<if test="(index % 999) == 998"> NULL ) OR t.ID IN (</if>#{item}
</foreach>)
</when>
<otherwise>
AND t.ID IN(NULL)
</otherwise>
</choose>
</where>
</select>
最后的语句可能是这样:where 1=1 and (id in(...) or id in(...))
是否需要加
原文:https://www.cnblogs.com/codetxj/p/14790609.html