@Override public page<productinfo> findAll (pageable pageable, ProductInfo productinfo) {//Create an action aggregation operations list<aggregationoperation> operations = new arraylist<> ();//Create a conditional class criteria criteria = new Criteria ();//The commodity status is not NULL if (Productinfo.getproductstatus ()!=null) {//productstatus equals the item status of the query added to the Operation aggregation operations Operations.add (Aggregation.match (Criteria.and ("Productstatus"). Is (Productinfo.getproductstatus ()))); } long totalcount = 0; Total pages if (operations!= null && operations.size () > 0) {//Operations aggregation Aggregation Aggregationcount = Newaggregation (Operations); Query the total number of data bars, return a collection aggregationresults<productinfo> Resultscount = Mongotemplate.aggregate (aggregationcount , "ProductInfo", Productinfo.class); TotalCount = Resultscount.getmappedresults (). Size (); }else{//Operation aggregation is empty, query the total number of data bars TotalCount = Mongotemplate.findall (productinfo.class). SiZe (); }//operation aggregation Add pages multiplied by each page size equals total number of pages Operations.add (Aggregation.skip ((Long) (Pageable.getpagenumber ()) * Pageable.getpagesize ()) );//Operation aggregation Add returns a page of data Operations.add (Aggregation.limit (Pageable.getpagesize ()));//Operation aggregation Add sort by solvecount descending//oper Ations.add (Aggregation.sort (Sort.Direction.DESC, "Solvecount")); Aggregation Aggregation = newaggregation (Operations);//query data by condition aggregationresults<productinfo> results = Mon Gotemplate.aggregate (Aggregation, "ProductInfo", productinfo.class);//The map and paging information and total number of records returned results return to new PAGEIMPL<> ;(results.getmappedresults (), pageable,totalcount); }
Conditional query for MONGO in Java