1

有人可以举一个例子 countQuery 在使用 Micronaut 数据进行显式查询(@Query)时实现分页吗?https://micronaut-projects.github.io/micronaut-data/latest/guide/#explicitQueries没有示例

我必须进行如下查询

@Query("From UserRelation where userId = :userId and itemId=:itemId", countQuery = <count query here>)
4

1 回答 1

1

你可以这样做:

@Query(
  value = "select relation_ from UserRelation relation_ where relation_.userId = :userId and relation_.itemId = :itemId", 
  countQuery = "select count(relation_) from UserRelation relation_ where relation_.userId = :userId and relation_.itemId = :itemId"
)

计数查询将相同,只有一次更改,它是子句中的count()函数。SELECT

于 2020-04-21T10:04:06.540 回答