spring boot jpa 分页

@Repository
public interface ProductRepository extends PagingAndSortingRepository<Product, Long> {}

继承PagingAndSortingRepository接口,其接口源码中包含page方法

public interface PagingAndSortingRepository<T, ID> extends CrudRepository<T, ID> {
    Iterable<T> findAll(Sort sort);

    Page<T> findAll(Pageable pageable);
}

Page<User> users = repository.findAll(PageRequest.of(0, 10));(注意pageNo从0开始

 

 记录一下,之前没怎么用过jpa.

 

posted @ 2021-12-17 09:24  张碧晨  阅读(70)  评论(0)    收藏  举报