获取Spring存储库中的Pageable自定义查询的总计数行数

ip6*_*696 7 java pagination spring-data-jpa spring-repositories

我实现这样的分页:

List<Products> products = productRepository.findAllProducts(productsRequest.getInitiatorType(), "ACTIVE",
      new PageRequest(page, 100, Sort.Direction.DESC, "insertDate"));
Run Code Online (Sandbox Code Playgroud)

但是如何获得此查询的总大小?只复制这样的查询?

  @Query("SELECT t FROM Products t WHERE t.isApproved = true AND t.partnerId = ?1 AND t.categories.status = ?2")
  List<OpcClProducts> findAllOpcClProducts(String senderId, String status, Pageable pageable);


  @Query("SELECT COUNT(t) FROM Products t WHERE t.isApproved = true AND t.partnerId = ?1 AND t.categories.status = ?2")
  long getTotalCount(String senderId, String status);
Run Code Online (Sandbox Code Playgroud)

并调用2个查询:for totalCount和数据?

Noi*_*xes 12

尝试将对象更改为

Page<Products> p .. 
Run Code Online (Sandbox Code Playgroud)

p应该包含您要查找的信息.:)(因为他们想让我发布在这里)^^'