美文网首页
Spring中的分页

Spring中的分页

作者: 疾风吧 | 来源:发表于2021-08-28 14:13 被阅读0次

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对象来得到分页信息

相关文章

网友评论

      本文标题:Spring中的分页

      本文链接:https://www.haomeiwen.com/subject/yfpbiltx.html