【问题标题】:Pageable usage with Query Annotation查询注释的可分页用法
【发布时间】:2020-01-19 12:39:32
【问题描述】:

我可以在 Spring Data R2dbc 存储库中使用带有 @Query 注释的 Pageable 属性吗?例如;

public interface PartyRepository extends ReactiveCrudRepository<Party,String> {

   @Query("select * from party order by id")
   Flux<Party> getParties(Pageable pageable);
}

它给出“org.springframework.data.repository.query.ParameterOutOfBoundsException : Invalid parameter index!您似乎声明的查询方法参数太少!”

有没有办法在 spring Data R2dbc 存储库中使用分页?

谢谢。

【问题讨论】:

    标签: r2dbc spring-data-r2dbc


    【解决方案1】:

    R2DBC 不支持,而且可能永远不会支持。

    但是您可以使用 SpEL 表达式手动调整查询字符串以包含分页。对于 MySQL,在您的示例中,这可能如下所示:

        @Query("SELECT * FROM party ORDER BY id LIMIT :#{[0].offset},:#{[0].pageSize}")
        Flux<Party> getParties(Pageable pageable);
    

    [0] 部分表示参数列表中的哪个参数是Pageable

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      • 1970-01-01
      • 2019-04-05
      • 1970-01-01
      • 2020-03-31
      • 2016-03-02
      相关资源
      最近更新 更多