对于长列表(例如 Oracle 有 1000 个项目的限制),您可以将其分隔为更多选择:
List<Long> listIds = Arrays.asList(1L, 2L, ..... , 10000L); // list with ids
String query = "select NOTE from NOTE where ID in (:listIds)";
List<String> noteListResult = new ArrayList<>();
int current = 0;
int iter = 100;
while (current < listIds.size()) {
Map<String, List<Long>> noteIdsMap = Collections.singletonMap("listIds",
listIds.subList(current, (current + iter > listIds.size()) ? listIds.size() : current + iter));
List<String> noteListIter = namedParameterJdbcTemplate.queryForList(query, noteIdsMap, String.class);
noteListResult.addAll(noteListIter);
current += iter;
}
return noteListResult;