Spring中的分页

Spring的分页类在spring-data-commons包里。

1. Pageable,PageRequest

Pageable: Abstract interface for pagination information. 分页信息的抽象。
PageRequest: Basic Java Bean implementation of Pageable. 对Pageable的基本实现。
属性page 页码,以0开始计数为首页,非负,
属性size 一页的大小,大于0,
属性Sort 排序。

常用方法:Pageable: next()下一页,previousOrFirst()前一页。
PageRequest: of(page, size, sort)

20200703155931652.png

2. Page,PageImpl

Page: A page is a sublist of a list of objects. It allows gain information about the position of it in the containing entire list. 列表的子集,包含了位置信息。
PageImpl: Page的基本实现。
PagePageImpl中都会用到Pageable

20200703160143692.png

3. @PageableDefault

默认的分页注解

    @GetMapping("/user")
    public List<User> query(@PageableDefault(page=2,size=17,sort="username,asc")Pageable pageable){//用spring自带的pageable对象来得到分页信息
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容