代码之家  ›  专栏  ›  技术社区  ›  Interlated

如何让pagerequest在带有注释的查询的Spring引导中工作

  •  0
  • Interlated  · 技术社区  · 6 年前

    我将从Spring Boot 1升级到Spring Boot 2。

    我只想挑出第一个结果。

    PageRequest pageRequest = PageRequest.of(0, batchSize, Sort.Direction.ASC, "id");
    

    在存储库上使用带注释的查询

    @Query("select c from Component")
    List<Component> findReturnComponent(PageRequest pageRequest);
    

    我收到这个错误消息

    but parameter 'Optional[pageRequest]' not found in annotated query 'select c from Component
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Anisuzzaman Babla Jayesh Elamgodil    6 年前

    使用可分页接口而不是pagerequest

    Pageable pageable = PageRequest.of(0, batchSize, Sort.Direction.ASC, "id");
    

    @Query("select c from Component")
    List<Component> findReturnComponent(Pageable pageable);