【发布时间】:2013-11-13 14:47:50
【问题描述】:
我对 Neo4j 比较陌生,并且对使用 spring 在 Neo4j 中编写动态查询有疑问。 根据我的阅读,查询在扩展 GraphRepository 类的接口中使用 @Query 参数进行注释,并且动态参数作为参数提供。
但我的要求是我必须动态生成 where 子句的数量。
For example,
@Query("match n where n.__type__='com.connectme.domain.Person' and n.age > {0} return n.id)
public List<Object> getPeopleWithAge(Integer age);//
我的查询也可以改变,其中年龄也可以小于某个值,在这种情况下,查询可以变成:
@Query("match n where n.__type__='com.connectme.domain.Person' and n.age > {0} and n.age <{1} return n.id)
public List<Object> getPeopleWithAge(Integer age1, Integer age2);//
以类似的方式,围绕年龄参数的许多子句会导致 where 子句的变化。 我如何动态处理这个问题,因为目前我只知道这种带注释的执行查询的方式。 我可以覆盖并编写自己的自定义查询吗?
【问题讨论】:
-
您也可以使用 Neo4j-Template.query 进行自定义查询或从 CypherDslRepository 继承并使用 CypherDSL
-
您能详细说明一下吗?我不熟悉 CypherDslREpository 是什么?
标签: neo4j cypher spring-data-neo4j