0

org.springframework.data.neo4j.annotation 包中的注解@Query 提供了某些计数属性,如countQuery、countQueryName。

/**
 * @return simpler count-query to be executed for @{see Pageable}-support {self} will be provided by the node-id of the current entity other parameters (e.g. {name}) by the given named params
 */
String countQuery() default "";

/**
 * @return name of the named count query to be used for this annotated method, instead of Class.method.count
 */
String countQueryName() default "";

有人可以解释一下这些的用法吗?更具体地说,我编写了一个查询来获取有关某个主题的帖子。查询结果将被分页。下面的查询工作正常,并给了我结果。

@Query("start post=node:__types__(className='com.xxx.entity.Post'), topic=node({0}) match post-[:TOPIC_POST]-topic return post")
Page<Post> getPostsByTopic(Topic topic, Pageable page);

现在我也想要结果总数,我是否必须为此编写另一个查询,或者有没有办法在其中容纳计数查询?

4

1 回答 1

1

我认为 countQuery 应该适合你,但你仍然需要编写 count 查询

如果要求分页结果返回正确的总计数,可以在 countQuery 属性中为 @Query 注释提供计数查询。此查询在结果查询之后单独执行,其结果用于填充返回页面的 totalCount 属性。

http://docs.spring.io/spring-data/neo4j/docs/current/reference/htmlsingle/#d0e2712

于 2013-09-30T07:07:02.103 回答