@Override
public Page<ProductInfo> findAll(Pageable pageable, ProductInfo productInfo) {
//创建一个操作聚合operations
List<AggregationOperation> operations = new ArrayList<>();
//创建一个条件类criteria
Criteria criteria = new Criteria();
//商品状态不为空
if (productInfo.getProductStatus()!=null){
   //productStatus等于查询的商品状态这个条件添加进操作聚合operations
operations.add(Aggregation.match(criteria.and("productStatus").is(productInfo.getProductStatus())));
}
long totalCount = 0;
//总页数
if (operations!= null && operations.size() > 0){
//操作聚合
Aggregation aggregationCount = newAggregation(operations);
//查询总的数据条数,返回一个集合
AggregationResults<ProductInfo> resultsCount = mongoTemplate.aggregate(aggregationCount, "productInfo", ProductInfo.class);
totalCount = resultsCount.getMappedResults().size();
}else{
//操作聚合为空,查询总的数据条数
totalCount = mongoTemplate.findAll(ProductInfo.class).size();
}
//操作聚合添加页数乘以每页大小等于总页数
operations.add(Aggregation.skip((long) (pageable.getPageNumber()) * pageable.getPageSize()));
//操作聚合添加返回一页的数据
operations.add(Aggregation.limit(pageable.getPageSize()));
//操作聚合添加根据solveCount降序排序
// operations.add(Aggregation.sort(Sort.Direction.DESC, "solveCount"));
Aggregation aggregation = newAggregation(operations);
//根据条件查询数据
AggregationResults<ProductInfo> results = mongoTemplate.aggregate(aggregation, "productInfo", ProductInfo.class);
//返回结果的map和分页信息和总记录数
return new PageImpl<>(results.getMappedResults(),pageable,totalCount);
}

  

最新文章

  1. 第十七篇:使用窗口的cache属性加速SOUI的渲染
  2. 每天一个linux命令(51):rcp命令
  3. min_free_kbytes
  4. XP与Win2003下网站配置
  5. struts2 注解方式
  6. RabbitMQ之安装
  7. TCP/IP协议学习(一)
  8. jenkins学习:jenkins+gitlab
  9. LinkedStack的底层实现
  10. jquery.cookie用法及其注意点
  11. 学习Acegi应用到实际项目中(1)
  12. 加盟阿里!贾扬清被曝从Facebook离职,任阿里硅谷研究院VP
  13. 词典的实现(3)--使用JAVA类库ArrayList实现Map数据结构
  14. luogu P1486 [NOI2004]郁闷的出纳员
  15. Android利用RecognizerIntent识别语音并简单实现打电话动作
  16. HDU 1513 &amp;&amp; POJ 1159 Palindrome (DP+LCS+滚动数组)
  17. StreamSets 部署 Pipelines 到 SDC Edge
  18. ubuntu4arm 网站参考
  19. C# AOP实现
  20. hdu 4741 Save Labman No.004 (异面直线的距离)

热门文章

  1. RemoteExt 远程验证
  2. MDK5使用技巧
  3. mybatis小工具
  4. 看图说说JVM GC收集算法
  5. ios9出现的问题
  6. (网络流)Food -- hdu -- 4292
  7. leetcode-8-String to Integer (atoi) (已总结)
  8. SpringMvc与Struts2的对比
  9. linux 流量统计
  10. Postgresql fillfactor