在JPA中提供了很方便的分页功能,那就是Pageable(org.springframework.data.domain.Pageable)以及它的实现类PageRequest(org.springframework.data.domain.PageRequest),详细的可以见示例代码。
1、改变CustomerRepository方法
1 2 3 4 5 6 7 8 9
扫描二维码关注公众号,回复:
3778485 查看本文章
10 11 12 |
|
2、增加CustomerController方法pageable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
从示例代码的注释当中可以看到Page对象的相关参数及值的说明,更详细的用法,参考PageRequest源码。
小结:怎么样,是不是很简单很方便?!
参考:
官方文档,http://docs.spring.io/spring-data/jpa/docs/current/reference/html/
DEMO,https://github.com/icnws/spring-data-jpa-demo
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。