如果对你有帮助, 请点击💖喜欢💖鼓励一下我这个臭弟弟
关键代码如下:
Query query = new Query(criteria);
List<Material> materialList = mongoTemplate.find(query, Material.class);
long count = materialList.size();
// 相当于limit(start, end)
query.skip(pageNumber*pageSize);
query.limit(pageSize);
PageRequest pageRequest = new PageRequest(pageNumber, pageSize, Sort.Direction.DESC, "creation");
List<Material> materials = mongoTemplate.find(query, Material.class);
//封装为视图对象
List<MaterialVo> materialVos = Lists.newArrayList();
for (Material material : materials)
{
materialVos.add(new MaterialVo(material, prefixURL));
}
Page page = new PageImpl(materialVos, pageRequest, count);
如果对你有帮助, 请点击💖喜欢💖鼓励一下我这个臭弟弟
网友评论