弹簧数据 JPA。从 Pageable 获取所有页面

Nuñ*_*ada 5 spring-data-jpa spring-boot

我有一个 SpringBoot 应用程序和一个从 CrudRepository

@Query("select cps from HotelPriceSummary cps where cps.price > 5 and cps.profilePercentage >= 70 ")
List<HotelPriceSummary> findMine(Pageable pageable);
Run Code Online (Sandbox Code Playgroud)

我想知道是否可以从对象中获取总页数 Pageable

Pat*_*ick 4

您可以使用Page<T>返回总元素的接口。

长的 -getTotalElements()

返回元素的总数。

您可以在文档中找到更多信息: PagePageImpl

在你的例子中它应该像这样工作:

@Query("select cps from HotelPriceSummary cps where cps.price > 5 and cps.profilePercentage >= 70 ")
Page<HotelPriceSummary> findMine(Pageable pageable);
Run Code Online (Sandbox Code Playgroud)