首先,我想你想说
params.put("code", codes); // on line 7
更重要的是,在我看来,仅在按 ID 查询节点时才支持传递列表。
不确定这是最好的解决方案,但它应该可以工作。它首先从您的参数构建一个 Lucene 查询,然后将其传递给您的 Neo4j 查询。
private void yourMethod() {
String request = "START sdg=node:Sfamilly({luceneQuery}) MATCH t-[CONTAINS_SF]->sdg RETURN count(distinct t) as count";
Map<String, Object> params = new HashMap<String, Object>();
List<String> codes = new ArrayList<String>();
codes.add("1234");
codes.add("12345");
params.put("luceneQuery", listToParams("master", codes));
Result<Map<String, Object>> resultMag = neo4jTemplate.query(request, params);
}
private String listToParams(String paramName, List<String> params) {
if (params.isEmpty()) {
throw new IllegalArgumentException("Empty params");
}
Iterator<String> paramsIterator = params.iterator();
StringBuilder builder = new StringBuilder(paramName).append(":").append(paramsIterator.next());
while (paramsIterator.hasNext()) {
builder.append(" OR ").append(paramName).append(":").append(paramsIterator.next());
}
return builder.toString();
}