Neo4j存储库-使用动态where子句编写查询

Neo4j存储库-使用动态where子句编写查询,neo4j,cypher,spring-data-neo4j,Neo4j,Cypher,Spring Data Neo4j,我对Neo4j比较陌生,对于使用spring在Neo4j中编写动态查询有疑问。 根据我所读的内容,查询在扩展GraphRespository类的接口中用@Query parameter进行注释,动态参数作为参数提供 但我的要求是,我必须动态生成where子句的数量 For example, @Query("match n where n.__type__='com.connectme.domain.Person' and n.age > {0} return n.id) public Li

我对Neo4j比较陌生,对于使用spring在Neo4j中编写动态查询有疑问。 根据我所读的内容,查询在扩展GraphRespository类的接口中用@Query parameter进行注释,动态参数作为参数提供

但我的要求是,我必须动态生成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);//
例如,
@查询(“匹配n,其中n.。\uuuu type_uuu='com.connectme.domain.Person'和n.age>{0}返回n.id)
公共列表getPeopleWithAge(整数年龄)//
我的查询也可以更改,其中年龄也可以小于某个值,在这种情况下,查询可以变成:

@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);//

@Query(“match n where n.uuu type_uuu='com.connectme.domain.Person'和n.age>{0}和n.age您可以编写自己的自定义查询逻辑。首先,您创建一个包含自定义查询方法的额外接口,这样就可以得到两个存储库接口

public interface YourRepository extends GraphRepository<SomeClass> implements YourRepositoryExtension{
    //inferred queries, annotated queries
}


public interface YourRepositoryExtension {
    EndResult<SomeClass> customQuery();
    Iterable<SomeClass> customTraversal();
}
公共接口YourRepository扩展GraphRespository实现YourRepositoryExtension{
//推断查询、注释查询
}
公共接口YourRepositoryExtension{
EndResult customQuery();
Iterable customTraversal();
}
然后进行一个实现:

@Repository
public class YourRepositoryImpl implements YourRepositoryExtension {

    @Autowired
    private YourRepository yourRepository;

    @Override
    public EndResult<SomeClass> customQuery(){
        //your query logic, using yourRepository to make cypher calls.
        return yourRepository.query("START n.. etc.. RETURN n", <optional params>);
    }

    @Override
    public Iterable<SomeClass> customTraversal(){
        SomeClass startNode = yourRepository.findOne(123);
        return yourRepository.findAllByTraversal(startNode, <some custom traversal>);
    }
}
@存储库
公共类YourRepositoryImpl实现YourRepositoryExtension{
@自动连线
私有存储库;
@凌驾
public EndResult customQuery(){
//您的查询逻辑,使用存储库进行密码调用。
返回您的repository.query(“START n..etc..return n”,);
}
@凌驾
公共Iterable customTraversal(){
SomeClass startNode=yourRepository.findOne(123);
返回您的存储库.findAllByTraversal(startNode,);
}
}

谢谢你的回复……但我还不完全理解……我该如何编写查询,以及我必须在YourRepositoryImpl类中实现GraphRespository?我已经更新了示例,使其更加详细。现在更清楚了吗?很抱歉回复太晚……但非常感谢你的解释。解决了一个困扰我的问题有一段时间。@w遗憾的是,由于GraphRespository不再包含query或findAllByTraversal方法,此方法不再有效。您是否碰巧对spring-neo4j v.5.1版有解决此问题的方法?您也可以使用neo4j-Template.query进行自定义查询,或者从CypsursLRepository继承并使用CypsursCold请详细说明一下?我不知道什么是CYPSORDRepository?