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