in超过了限制个数

mybatisPlus

private void cutInParameter(QueryWrapper<Object> qw, List<String> ids) {
        List<List<String>> idList = ListUtils.partition(ids, 500);
        if(idList.size() == 0) {
            return;
        } else {
            qw.and(param -> {
                for(int i = 0; i < idList.size(); i++) {
                    param.or().in("id", idList.get(i));
                }
            });
        }
    }

mybatis

<if test="ids!=null and ids!=''">
            AND (bpi.id IN
            <foreach collection="ids" index="index" item="id" open="(" close=")">
            <if test="index != 0">
                <choose>
                    <when test="index % 500 == 0"> ) OR bpi.id in( when>
                    <otherwise>,otherwise>
                choose>
            if>
                #{id}
            foreach>
            )
        if>

字符串拼接

private String splitIn(String fieldName,List<String> ids) {
        List<List<String>> lists = Lists.partition(ids, 500);
        StringBuilder sb = new StringBuilder();
        sb.append("( ");
        for (int i = 0; i < lists.size(); i++) {
            sb.append(fieldName);
            sb.append(" in (' ");
            sb.append(String.join("','", lists.get(i)));
            if (i != lists.size()-1){
                sb.append(" ') ");
                sb.append("or ");
            }
        }
        sb.append(" ') )");
        return sb.toString();
    }

你可能感兴趣的:(java,java)