您的位置:首页 > 数据库 > Mongodb

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

2019-03-12 20:24 411 查看

//分页查询
@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);//删除符合条件的全部记录
*/
}

|

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐