由于sqlserver 或其他数据库in查询条件长度或者个数限制,如果不想sql太复杂嵌套查询的话,可使用java分堆操作
/** * 将集合分割成指多个集合 * @param list * @param len * @return */ public static <T> List<List<T>> splitList(List<T> list, int len) { if (list == null || list.size() == 0 || len < 1) { return null; } int size = list.size(); int count = (size + len - 1) / len; List<List<T>> result = new ArrayList<>(count==1?size:len); for (int i = 0; i < count; i++) { List<T> subList = list.subList(i * len, (Math.min((i + 1) * len, size))); result.add(subList); } return result; }