springboot中怎么利用Jpa 实现分页功能
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,本篇文章给大家分享的是有关springboot中怎么利用Jpa 实现分页功能,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。Springb
千家信息网最后更新 2025年12月02日springboot中怎么利用Jpa 实现分页功能
实体类
本篇文章给大家分享的是有关springboot中怎么利用Jpa 实现分页功能,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
Springboot 集成 Jpa 实现分页
由于用的技术并不复杂,所以我们开门见山,直接上代码
先来看下代码结构
pom.xml 引入相关jar包
4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.4.RELEASE com.example springboot-blog 0.0.1-SNAPSHOT springboot-blog Blog project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web junit junit mysql mysql-connector-java runtime org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.springframework.boot spring-boot-maven-plugin
application.properties配置
# 配置数据源spring.datasource.url=jdbc:mysql://localhost:3306/blog_systemspring.datasource.username=rootspring.datasource.password=root#基本配置spring.application.name=springboot-blogserver.port=8080# 显示sqlspring.jpa.show-sql=true
实体类Article
@Data@ToString@Entity@Table(name = "t_article")public class Article { @Id private Integer id; @Column(name = "title") private String title; @Column(name = "content") private String content; @Column(name = "created") private Date created; @Column(name = "modified") private Date modified; @Column(name = "categories") private String categories; @Column(name = "tags") private String tags; @Column(name = "allow_comment") private Integer allowComment; @Column(name = "thumbnail") private String thumbnail;}ArticleDao层实现
public interface ArticleDao extends JpaRepository{}
Article Service 层
ArticleService接口
public interface ArticleService { Page getArticleWithPage(Integer page, Integer size);} ArticleServiceImpl实现类
@Service@Slf4jpublic class ArticleServiceImpl implements ArticleService { @Autowired private ArticleDao articleDao; @Override public Page getArticleWithPage(Integer page, Integer size) { log.info("page is {}, size is {}", page, size); if (page <= 0) { page = 1; } Pageable pageRequest = PageRequest.of(page - 1, size); return articleDao.findAll(pageRequest); }} ArticleController 控制层实现
@Controller@Slf4j@RequestMapping("/article")public class ArticleController { @Autowired private ArticleService articleService; @RequestMapping("/index") public String toIndex(Model model, @RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "size", defaultValue = "3") Integer size) { Page articles = articleService.getArticleWithPage(page, size); model.addAttribute("articles", articles); return "/client/index"; }} 页面核心代码
效果展示

以上就是springboot中怎么利用Jpa 实现分页功能,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。
代码
配置
功能
文章
更多
知识
篇文章
复杂
实用
开门见山
个人
博客
后台
基本配置
实体
小站
就是
工作会
技术
接口
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
周村食品管理软件开发
游戏软件开发与运营
数据库查看监听程序
航天软件开发过程
1u服务器机箱生产
重庆邮电网络安全读研怎样
表示网络安全的图
电度表服务器双机冗余配置
三国志前往新服务器原有的武将
服务器命令方块放哪
linux服务器程序
浙江特色软件开发创新服务
数据库安全性保护机制的是
服务器管理器打开iis
浪潮服务器机柜
广西建设学院计算机网络技术
ctp期货交易软件开发
计算机数据库前提
看门狗2 ctos数据库
2018互联网大会创略科技
三维管理软件开发
共建网络安全主题活动
服务器ip怎么限制内网访问
数据库幻读定义
中国三银新石材数据库
北京师范大学服务器云主机
网络安全法治多少日起施行
为什么北京软件开发工资高
从乌克兰危机看网络安全的重要性
网络安全人人有责人人参与