Java代码操作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);//删除符合条件的全部记录
*/	
  }	

|

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

听风动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值