MySQL解决in个数超过1000失效的问题

MySQL解决in个数超过1000失效的问题

// 解决in个数超过1000的问题

List<Long> buildingIds = (List<Long>)params.get("buildingIds");

if(ValidateUtil.collectionsIsNotEmpty(buildingIds)){

List<String> setList = new ArrayList<String>(0);

Set<Long> set = new HashSet<Long>();

StringBuffer stringBuffer = new StringBuffer(" and (d.convert_room_id in (");

for (int i = 1; i <= buildingIds.size(); i++) {

set.add(buildingIds.get(i - 1));

if (i % 900 == 0) {//900为阈值

setList.add(StringUtils.join(set.iterator(), ","));

set.clear();

}

}

if (!set.isEmpty()) {

setList.add(StringUtils.join(set.iterator(), ","));

}

stringBuffer.append(setList.get(0));

for (int j = 1; j < setList.size(); j++) {

stringBuffer.append(") or d.convert_room_id in (");

stringBuffer.append(setList.get(j));

}

stringBuffer.append("))");

sb.append(stringBuffer.toString());

}