Spring boot 使用jpa分页查询,不需要写SQL语句, 正确使用 Pageable,以及 Page<T>转换为List
使用了spring boot配合jpa,感觉是挺不错的。做一个简单的mysql数据库分页查询很简单,直接上代码了。import org.springframework.data.domain.Page;import org.springframework.data.domain.PageRequest;import org.springframework.data.domain.Pa...
·
使用了spring boot配合jpa,感觉是挺不错的。做一个简单的mysql数据库分页查询
很简单,直接上代码了。
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
//就不用写注释了吧。
Pageable pageable = PageRequest.of(Integer.parseInt(page), Integer.parseInt(limit));
Page<PicInfo> allPicturesPage = picDao.findAll(pageable);
List<PicInfo> allPictures = allPicturesPage.getContent();
之前用 Pageable pageable = new PageRequest(params) 的方法已经过时了,用 PageRequest.of 来代替了。
更多推荐
所有评论(0)