Micronaut 数据的计数查询示例 @Query
Example count query for Micronaut data @Query
有人可以举例说明 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>)
你可以这样做:
@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"
)
计数查询将相同,只需更改一处,即SELECT
子句中的count()
函数。
有人可以举例说明 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>)
你可以这样做:
@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"
)
计数查询将相同,只需更改一处,即SELECT
子句中的count()
函数。