解决思路
1. 先在service层中将数据分割不超过上限999的list集合,然后再传给dao层查询
2. 直接在sql中处理
本人尝试了第一种,觉得比较麻烦,所以这里提供第二种,只需要在动态sql中进行处理的思路
动态sql
List<AccountsPO> findXXXByOrgIds(@Param("Ids") List<String> Ids);
<select id="findXXXByIds"
resultType="com.XXX.XXX.AccountPO">
select t.* from table t
<where>
<!--注意:一定要判断Ids.size>0 否则若list为长度为空的 数组 则会失败 -->
<if test="Ids != null and Ids.size>0">
(t.id in
<foreach collection="Ids" item="item" open="(" close=")" index="index">
<if test="index != 0">
<choose>
<when test="index % 1000 == 999">) OR t.id IN(</when>
<otherwise>,</otherwise>
</choose>
</if>
#{item}
</foreach>)
</if>
</where>
</select>
最终的拼接效果即
select t.* from table t where t.id in (0,1,2,...998) or t.id in (999,1000,...)