spring boot自带的page分页问题怎么解决(page,springboot,开发技术)

时间:2024-05-08 00:30:52 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

#jpa自带的page类()springboot自带

帮助我们分页

publicPage<Comment>findByDetailid(Longid,Pageablepageable);

括号中第一个属性表示根据什么性质排列,第二个属性为保存你分页的配置

在controller层

@RequestMapping("find/{id}/{page}")publicPage<Comment>getPageComments(@PathVariable("id")Longid,@PathVariable("page")Integerpage){Pageablepageable=newPageRequest(page,3,Sort.Direction.ASC,"id");Page<Comment>ls=commentRepository.findByDetailid(id,pageable);returnls;}

第一个参数表示页数,第一页从0开始,第二个参数为一页包含几条内容

Sort.Direction.ASC表示排序方向为从小到大,最后一个是排序的根据

在浏览器中还可以帮我们传出totalElements: 21 totalPages: 7 last:false一共多少条及,一共多少页当前页是否为最后一页

##class选择器class='page-numbers'id=pagenum$(".page-numbers")

SpringBoot分页查询

前段时间公司要求重构以前的代码,于是将公司自动巡检相关的代码使用SpringBoot框架进行了重构工作,在此过程中遇到的一个觉得值分享的内容,是关于SpringBoot中利用JPA进行分页查询的功能,我就列举比较重要或容易出错的配置了,其余的配置就不详细介绍:

JPA在yml中的配置内容

spring boot自带的page分页问题怎么解决

图上是JPA的简单配置,值得注意的是:properties.hibernate.dialect:org.hibernate.dialect.Oracle10gDialect 这项配置的是指定的数据库方言,如果未配置,程序运行会出错。

DAO层的接口

spring boot自带的page分页问题怎么解决

看图,要实现分页必须继承JpaSpecificationExecutor

分页查询

spring boot自带的page分页问题怎么解决

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:spring boot自带的page分页问题怎么解决的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:idea中All和Thread的区别是什么下一篇:

3 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18