select * from test_table where 1 = 1 <!-- IdList --> <if test="IdList != null and IdList.size > 0"> AND PK_ID IN <!-- 处理in的集合超过1000条时Oracle不支持的情况 --> <trim suffixOverrides=" OR PK_ID IN()"> <!-- 表示删除最后一个条件 --> <foreach collection="IdList" item="Id" index="index" open="(" close=")"> <if test="index != 0"> <choose> <when test="index % 1000 == 999">) OR PK_ID IN (</when> <otherwise>,</otherwise> </choose> </if> #{Id} </foreach> </trim>