分享

springdata之PagingAndSortingRepository实现分页功能

 魏祖清 2016-09-22
PersonRepsotory接口
public interface PersonRepsotory extends PagingAndSortingRepository<Person, Integer> {}
具体实现
@Test
public void PagingAndSortingRepository() {
// pageNo从0开始
int pageNo = 6 - 1;
int pageSize = 5;
// PageRequest接口通常使用的起PageRequest实现类,其中封装了需要分页的信息
PageRequest pageRequest = new PageRequest(pageNo, pageSize);
Page<Person> page = personRepsotory.findAll(pageRequest);
System.out.println("总记录数:" + page.getTotalElements());
System.out.println("当前第几页:" + page.getNumber());
System.out.println("总页数" + page.getTotalPages());
System.out.println("当前页面的list:" + page.getContent());
System.out.println("当前页面记录数:" + page.getNumberOfElements());
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多