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

我实现这样的分页:

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

但是,如何获取此查询的总大小?只有像这样的重复查询?

  @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);

并调用 2 查询:对于 totalCount 和 data?


答案 1

尝试将对象更改为

Page<Products> p .. 

p应该有你正在寻找的信息。:)(张贴在这里,因为他们希望我这样做)^^'


答案 2