15

我这样实现分页:

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 和对于数据?

4

1 回答 1

21

尝试将您的对象更改为

Page<Products> p .. 

p 应该有您正在寻找的信息。:) (发布在这里是因为他们想要我)^^'

于 2018-02-02T12:51:27.290 回答