Spring Data Neo4j可分页 [英] Spring Data Neo4j Pageable

查看:1178
本文介绍了Spring Data Neo4j可分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Data Repository接口,它使用自定义查询从数据库中获取节点集合:

I have a Spring Data Repository interface that gets a collection of nodes from by database using a custom query:

存储库方法:

@Query ("START r = node({0}) MATCH r <-[:AUTHOR]-  m RETURN m")
public Page<Object> findObjectById (long objectId,Pageable pageable);

方法调用

 custRepository.findObjectById (4,new PageRequest(0, 5));

这将返回一个对象集合,但页面信息不正确。数据库中有足够的数据供我获取多页数据。第一页信息表示:

This return a collection of Objects, however the Page information is incorrect. There is enough data in database for me to get several pages of data. The first Page information is saying that there is:

 Current Page #: 0
 Total Pages: 1
 Is First Page: true
 Is last Page: true

但是当我拿到第二页页面我仍然收到其他对象的集合,然后页面信息变为:

However when I fetch the second page I am still getting a collection of the other objects and the page information then becomes:

 Current Page #: 1
 Total Pages: 6
 Is First Page: false
 Is last Page: false

这清楚地表明第一页上的页面信息不正确,因为我需要准确的信息来在我的应用程序中实现分页,这就成了一个问题。是什么导致了这个问题,我该如何解决?

This clearly show that the page information on the first page is incorrect and since I need accurate information to implement pagination in my app this becomes a problem. What is causing this problem and how do I fix it?

推荐答案

我提出了同样的问题。事实证明,您还必须指定查询注释的countQuery属性。不确定它是否有错误记录。在你的情况下,它应该是

I hand the same problem. Turns out you have to also specify the countQuery attribute of the query annotation. Not sure if its a bug or not so well documented. In your case it should be

@Query (value="START r = node({0}) MATCH r <-[:AUTHOR]-  m RETURN m", 
        countQuery="START r = node({0}) MATCH r <-[:AUTHOR]-m RETURN count(m)")

希望对您有帮助。

这篇关于Spring Data Neo4j可分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆