gpt4 book ai didi

spring - 使用 Spring Data Graph/Neo4j 进行分页

转载 作者:行者123 更新时间:2023-12-04 18:20:07 24 4
gpt4 key购买 nike

当使用 Spring Data Graph (Neo4J) 作为数据存储时,是否可以获取 Page 结果?

findAll(Pageable) 似乎是使用 GraphRepository 时唯一可用的 Pageable 查询。我正在寻找的是用于其他 findBy***() 查询的 Pageable API。

也许,可能有一种完全不同(推荐)的方式来使用 Spring Data Graph 来对结果进行分页。也欢迎对此提出想法!

最佳答案

Spring Data Neo4j(2.0 目前在 SNAPSHOT 但很快 RC1)添加了对派生和注释查询的页面支持。 findAll() 继承自 CRUD-Repository。

我们可以添加对默认查询方法的页面支持。你能提出一个JIRA issue吗?为此?

派生和 @Query 注释页面方法的示例。

interface UserRepository extends GraphRepository<User> {
// derived method
Page<User> findByTag(String tag, Pageable page);
@Query("start user=node({0}) match user-[r:RATED]-product where r.stars > 3 return product order by r.stars desc")
Page<Product> getRatedProducts(User user);
}

只需将 cypher(或 gremlin)添加为您的应用程序的依赖项:

<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-cypher</artifactId>
<version>${neo4j.version}</version>
</dependency>

关于spring - 使用 Spring Data Graph/Neo4j 进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8028701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com