当前位置:   article > 正文

Java代码操作mongodb数据库进行简单的分页查询_java mongoclient操作mongodb分页查询文档

java mongoclient操作mongodb分页查询文档

//分页查询
@RequestMapping(“findCloudListPage”)
@ResponseBody
public JSONObject findCloudListPage(Integer page,Integer rows,HttpSession session,String id){
JSONObject jsonObject = new JSONObject();
Query query=new Query();
query.addCriteria(Criteria.where(“pid”).is(id));
//查总条数
long count=mongoTemplate.count(query,CloudDiskBean.class);
query.with(new Sort(new Order(Direction.DESC,“createTime”)));//排序
query.skip((page-1)*rows);//跳过前几页
query.limit(rows);
List find = mongoTemplate.find(query,CloudDiskBean.class);
jsonObject.put(“total”, count);
jsonObject.put(“rows”, find);
return jsonObject;

	/*//获取连接 
	  MongoClient client=new MongoClient(); 
	  //得到数据库 
	  MongoDatabase database = client.getDatabase("itcastdb"); 
	  //得到集合封装对象 
	  MongoCollection<Document> collection = database.getCollection("student"); 
	  BasicDBObject bson=new BasicDBObject("name", "铁扇公主"); 
	  collection.deleteOne(bson);//删除记录(符合条件的第一条记录) 
	  //collection.deleteMany(bson);//删除符合条件的全部记录
*/	
  }	
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

|

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/56067
推荐阅读
相关标签
  

闽ICP备14008679号