码迷,mamicode.com
首页 > 数据库 > 详细

springboot jpa mongodb 多条件分页查询

时间:2018-03-20 20:48:36      阅读:1742      评论:0      收藏:0      [点我收藏+]

标签:status   pos   count   tar   stat   list   operator   opera   create   

public Page<Recorded> getRecordeds(Integer page, Integer size, Recorded recorded) {

        if (page<1){

            page=1;

        }

        Sort sort = new Sort(Sort.Direction.DESC,"createTime");

        Pageable pageable = new PageRequest(page-1,size,sort);

        Query query = new Query();

        //条件id =XX

        Criteria criteria = Criteria.where("callerId").is(recorded.getCallerId());

criteria.and(“status”).is(Recorded.SUCCESS);

if(startTime!=null&&endTime!=null){

            criteria.andOperator(

                    Criteria.where("createTime").gte(startTime),

                    Criteria.where("createTime").lte(endTime)

            );

        }

query.addCriteria(criteria);

 

        //mongoTemplate.count计算总数

        long total = mongoTemplate.count(query, Recorded.class);

        

        // mongoTemplate.find 查询结果集

        List<Recorded> items = mongoTemplate.find(query.with(pageable), Recorded.class);

 

        return new PageImpl(items, pageable, total);

 

    }

springboot jpa mongodb 多条件分页查询

标签:status   pos   count   tar   stat   list   operator   opera   create   

原文地址:https://www.cnblogs.com/fswhq/p/jpa_mongodb.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!