Thymeleaf+Bootstrap封装分页组件

2024-08-22 23:52

本文主要是介绍Thymeleaf+Bootstrap封装分页组件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

代码

templates/components/pagination.html

<!doctype html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<body>
<div class="d-flex justify-content-between align-items-center mb-3" th:fragment="pagination(current,pageSize,rows,path)"><th:block th:with="pages = ${rows%pageSize==0?rows/pageSize:rows/pageSize+1}"><div><span th:text="${pages}"/><span th:text="${rows}"/> 条数据</div><div><!--有数据:总页数大于1--><th:block th:if="${pages >= 1}"><ul class="col pagination mb-0"><li class="page-item" th:classappend="${current == 1} ? 'disabled'"><a class="page-link" th:href="@{${path}(pageNo=${current - 1})}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li><!--总页数小于8--><th:block th:if="${pages < 8}" th:each="page:${#numbers.sequence(1,pages)}"><li th:class="${page == current ? 'page-item active':'page-item'}"><a class="page-link" th:href="@{${path}(pageNo=${page})}" th:text="${page}" th:title="|第${page}页|"></a></li></th:block><!--总页数大于等于8--><th:block th:if="${pages >= 8}"><!--当前页小于5--><th:block th:if="${current < 5}"><!--前4页--><th:block th:each="page:${#numbers.sequence(1,4)}"><li th:class="${page == current ? 'page-item active':'page-item'}"><a class="page-link" th:href="@{${path}(pageNo=${page})}" th:text="${page}" th:title="|第${page}页|"></a></li></th:block><!--5、6页--><li class="page-item"><a class="page-link" th:href="@{${path}(pageNo=5)}" title="第5页">5</a></li><li class="page-item"><a class="page-link" th:href="@{${path}(pageNo=6)}" title="第6页">6</a></li><!--分隔符--><li class="page-item mx-2" disabled="">...</li><!--最后页--><li class="page-item"><a class="page-link" th:href="@{${path}(pageNo=${pages})}" th:text="${pages}" th:title="|第${pages}页|"></a></li></th:block><!--当前页大于等于5--><th:block th:if="${current >= 5}"><!--当前页小于等于倒数第5--><th:block th:if="${current <= pages - 5}"><!--第1页--><li class="page-item"><a class="page-link" th:href="@{${path}(pageNo=1)}" title="第1页">1</a></li><!--分隔符--><li class="page-item mx-2" disabled="">...</li><!--中间5页--><li class="page-item"><a class="page-link" th:href="@{${path}(pageNo=${current - 2})}" th:text="${current - 2}" th:title="|第${current - 2}页|"></a></li><li class="page-item"><a class="page-link" th:href="@{${path}(pageNo=${current - 1})}" th:text="${current - 1}" th:title="|第${current - 1}页|"></a></li><li class="page-item active"><a class="page-link" th:href="@{${path}(pageNo=${current})}" th:text="${current}" th:title="|第${current}页|"></a></li><li class="page-item"><a class="page-link" th:href="@{${path}(pageNo=${current + 1})}" th:text="${current + 1}" th:title="|第${current + 1}页|"></a></li><li class="page-item"><a class="page-link" th:href="@{${path}(pageNo=${current + 2})}" th:text="${current + 2}" th:title="|第${current + 2}页|"></a></li><!--分隔符--><li class="page-item mx-2" disabled="">...</li><!--最后页--><li class="page-item"><a class="page-link" th:href="@{${path}(pageNo=${pages})}" th:text="${pages}" th:title="|第${pages}页|"></a></li></th:block><!--当前页大于倒数第5--><th:block th:if="${current > pages - 5}"><!--第1页--><li class="page-item"><a class="page-link" th:href="@{${path}(pageNo=1)}" title="第1页">1</a></li><!--分隔符--><li class="page-item mx-2" disabled="">...</li><!--后6页--><th:block th:each="page:${#numbers.sequence(pages - 5,pages)}"><li th:class="${page == current ? 'page-item active':'page-item'}"><a class="page-link" th:href="@{${path}(pageNo=${page})}" th:text="${page}" th:title="|第${page}页|"></a></li></th:block></th:block></th:block></th:block><li class="page-item" th:classappend="${current == pages} ? 'disabled'"><a class="page-link" th:href="@{${path}(pageNo=${current + 1})}" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li></ul></th:block></div></th:block>
</div>
</body>
</html>

使用

<div th:replace="~{components/pagination::pagination(${page.current}, ${page.size}, ${page.total}, @{/admin/user/list(name=${name},email=${email},inTime1=${inTime1},inTime2=${inTime2})})}"></div>

这篇关于Thymeleaf+Bootstrap封装分页组件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1097761

相关文章

Golang如何对cron进行二次封装实现指定时间执行定时任务

《Golang如何对cron进行二次封装实现指定时间执行定时任务》:本文主要介绍Golang如何对cron进行二次封装实现指定时间执行定时任务问题,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录背景cron库下载代码示例【1】结构体定义【2】定时任务开启【3】使用示例【4】控制台输出总结背景

Golang如何用gorm实现分页的功能

《Golang如何用gorm实现分页的功能》:本文主要介绍Golang如何用gorm实现分页的功能方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录背景go库下载初始化数据【1】建表【2】插入数据【3】查看数据4、代码示例【1】gorm结构体定义【2】分页结构体

Python中对FFmpeg封装开发库FFmpy详解

《Python中对FFmpeg封装开发库FFmpy详解》:本文主要介绍Python中对FFmpeg封装开发库FFmpy,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、FFmpy简介与安装1.1 FFmpy概述1.2 安装方法二、FFmpy核心类与方法2.1 FF

Mybatis的分页实现方式

《Mybatis的分页实现方式》MyBatis的分页实现方式主要有以下几种,每种方式适用于不同的场景,且在性能、灵活性和代码侵入性上有所差异,对Mybatis的分页实现方式感兴趣的朋友一起看看吧... 目录​1. 原生 SQL 分页(物理分页)​​2. RowBounds 分页(逻辑分页)​​3. Page

Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析

《Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析》InstantiationAwareBeanPostProcessor是Spring... 目录一、什么是InstantiationAwareBeanPostProcessor?二、核心方法解

C++ RabbitMq消息队列组件详解

《C++RabbitMq消息队列组件详解》:本文主要介绍C++RabbitMq消息队列组件的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. RabbitMq介绍2. 安装RabbitMQ3. 安装 RabbitMQ 的 C++客户端库4. A

如何更改pycharm缓存路径和虚拟内存分页文件位置(c盘爆红)

《如何更改pycharm缓存路径和虚拟内存分页文件位置(c盘爆红)》:本文主要介绍如何更改pycharm缓存路径和虚拟内存分页文件位置(c盘爆红)问题,具有很好的参考价值,希望对大家有所帮助,如有... 目录先在你打算存放的地方建四个文件夹更改这四个路径就可以修改默认虚拟内存分页js文件的位置接下来从高级-

MyBatis分页插件PageHelper深度解析与实践指南

《MyBatis分页插件PageHelper深度解析与实践指南》在数据库操作中,分页查询是最常见的需求之一,传统的分页方式通常有两种内存分页和SQL分页,MyBatis作为优秀的ORM框架,本身并未提... 目录1. 为什么需要分页插件?2. PageHelper简介3. PageHelper集成与配置3.

PyQt6中QMainWindow组件的使用详解

《PyQt6中QMainWindow组件的使用详解》QMainWindow是PyQt6中用于构建桌面应用程序的基础组件,本文主要介绍了PyQt6中QMainWindow组件的使用,具有一定的参考价值,... 目录1. QMainWindow 组php件概述2. 使用 QMainWindow3. QMainW

一文详解如何在Vue3中封装API请求

《一文详解如何在Vue3中封装API请求》在现代前端开发中,API请求是不可避免的一部分,尤其是与后端交互时,下面我们来看看如何在Vue3项目中封装API请求,让你在实现功能时更加高效吧... 目录为什么要封装API请求1. vue 3项目结构2. 安装axIOS3. 创建API封装模块4. 封装API请求