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

mongodb操作

时间:2019-07-20 18:41:02      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:record   分页查询   highlight   ring   string   iter   add   div   one   

mongodb 的分页查询:

   public  List<NoticeSentRecordDto> select(NoticeSelectInfo noticeSelectInfo){
        Query query = new Query().with(new Sort(Sort.Direction.DESC, "createTime"));
        if (noticeSelectInfo.getCurrPage() != null && noticeSelectInfo.getPageSize() != null) {
            query.skip((noticeSelectInfo.getCurrPage()-1)*noticeSelectInfo.getPageSize())
                    .limit(noticeSelectInfo.getPageSize());
        }
        query.addCriteria(Criteria.where("isDeleted").is(0));
        if(!StringUtils.isEmpty(noticeSelectInfo.getType())){
            query.addCriteria(Criteria.where("type").is(noticeSelectInfo.getType()));
        }
        return template.find(query, NoticeSentRecordDto.class);
    }

查询个数:

template.count(query,NoticeSentRecordDto.class);

根据id修改一条记录,并返回:
 public  NoticeSentRecordDto selectOne(NoticeSelectInfo noticeSelectInfo){
        Query query = new Query();
        query.addCriteria(Criteria.where("_id").is(noticeSelectInfo.getId()));
        Update update = new Update().set("isRead", true);
        template.updateFirst(query, update, NoticeSentRecordDto.class);
        return template.findOne(query, NoticeSentRecordDto.class);
    }

  

mongodb操作

标签:record   分页查询   highlight   ring   string   iter   add   div   one   

原文地址:https://www.cnblogs.com/z360519549/p/11218704.html

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