好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

spring boot自带的page分页问题

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

帮助我们分页

?

1

public Page<Comment> findByDetailid(Long id,Pageable pageable);

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

在controller层

?

1

2

3

4

5

6

@RequestMapping ( "find/{id}/{page}" ) 

     public Page<Comment> getPageComments ( @PathVariable ( "id" ) Long id, @PathVariable ( "page" ) Integer page){

         Pageable pageable = new PageRequest(page, 3 , Sort.Direction.ASC, "id" );

         Page<Comment> ls=commentRepository.findByDetailid(id,pageable);

         return ls;

     }

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

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

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

?

1

2

## class 选择器

class = 'page-numbers' id=pagenum $( ".page-numbers" )

springboot分页查询

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

JPA在yml中的配置内容

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

DAO层的接口

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

分页查询

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

原文链接:https://blog.csdn.net/weixin_43289689/article/details/87969141

查看更多关于spring boot自带的page分页问题的详细内容...

  阅读:20次