mongodb criteria查询

http://blog.csdn.net/ni_hao_ya/article/details/26384467

  1. //is相当于等于  
  2. //in相当于sql中的in  
  3. //ne相当于不等于  
  4. //orOperator接受多个条件,组成or逻辑  
  1. query.addCriteria(Criteria.where("modelId").ne("").ne(null));  
  2. query.with(new Sort(new Order(Direction.DESC, "ct")));  
  1. Query query=new Query();  
  2. Criteria criteria=Criteria.where("name").is("tom")
  3.                            .and("studentNum").in(numberList);  
  4. query.addCriteria(criteria);  
[java]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. new Query(criteria);  
[java]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. Criteria criteria=Criteria.where("indexWarnGrade").ne("0")
  2.                            .orOperator(Criteria.where("resId")
  3.                            .is(channelId),
  4. Criteria.where("resBelongChannelId").is(channelId));  
  5. query.addCriteria(criteria);  
  6. query.with(new Sort(Direction.DESC, "indexWarnLatelyDate"));  
[java]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. //分页  
  2. int currentPage = (initPagingBean.getStart()/initPagingBean.getPageSize())+1;  
  3. Query query=new Query();  
  4.         //查询通道和通道下属的设备告警信息  
  5.         Criteria criteria=Criteria.where("indexWarnGrade").ne("0")
  6.               .orOperator(Criteria.where("resId")
  7.               .is(channelId)
  1.   Criteria.where("resBelongChannelId").is(channelId));  
  2.         query.addCriteria(criteria);  
  3.         query.with(new Sort(Direction.DESC, "indexWarnLatelyDate"));  
  4.         int total = (intthis.realMongodbServiceImpl.
  5.               findCount(MonitorObject.class, query);  
  6.         initPagingBean.setTotalItems(total);  
  7.  //查询mo集合  
  8.  List<MonitorObject> moList=this.realMongodbServiceImpl.
  9. findList(MonitorObject.class, query, currentPage, initPagingBean.getPageSize());         
  10.   
  11. initPagingBean.setDataList(wvList);  
  12. return  initPagingBean;  

多个字段排序:第一排序按照sort降序,第二排序按照ct降序

  1. query.with(new Sort(new Order(Direction.DESC, "sort"))
  2.              .and(new Sort(Direction.DESC,"ct")));                                
  3. //query.sort().on("xxx", Order.DESCENDING);    
  4. //query.sort().on("xxx", Order.ASCENDING);    
  5.                  

猜你喜欢

转载自1634801662.iteye.com/blog/2292519