spring boot+thymeleaf+semantic ui 分页

参考:

https://my.oschina.net/ayyao/blog/898041

后端 springboot 使用:

com.github.pagehelper.PageInfo,作为分页对象

java 复制代码
<!--引入分页插件-->
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.12</version>
</dependency>

controller里代码:

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

String orderBy = "id desc";
PageHelper.startPage(pageNum, 10, orderBy);
List<User> users = userService.list();
if (users != null) {
    PageInfo<Type> pageInfo = new PageInfo<>(types);
    model.addAttribute("pageInfo", pageInfo);
}

前端分页代码:

html 复制代码
<tfoot>
  <tr>
    <th colspan="6" >

      <!--分页条 begin-->
      <div class="ui left floated pagination mini menu">
        <!-- 首页 -->
        <a th:href="@{/sss/userapi(pageNum=1)}" class="icon item" >首页</a>
        <!-- 上一页previous -->
        <a th:if="${pageInfo.hasPreviousPage}" class="icon item" th:classappend="${pageInfo.pageNum}==0 ? 'disabled' : ''"
           th:href="@{/sss/userapi(pageNum=${pageInfo.prePage})}">
          <i class="angle left icon">上一页</i>
        </a>
        <!-- 中间页面1-10页面-->
        <div th:each="p : ${pageInfo.navigatepageNums}">
          <a class="icon item" th:classappend="${pageInfo.pageNum}==${p} ? 'disabled' : ''"
             th:href="@{/sss/userapi(pageNum=${p})}">
            <i th:text="${p}"></i>
          </a>
        </div>

        <!-- 下一页next -->
        <a th:if="${pageInfo.hasNextPage}" class="icon item"
           th:href="@{/sss/userapi(pageNum=${pageInfo.nextPage})}">
          下一页<i class="angle right icon"></i>
        </a>
        <!-- 尾页 -->
        <a th:href="@{/sss/userapi(pageNum=${pageInfo.pages})}" class="icon item" >尾页</a>
      </div>
      <!--分页条 end-->

    </th>
  </tr>
</tfoot>

首页、中间页、尾页样式:

其他:

Thymeleaf循环语句_thymeleaf 循环_苦海无边,不能上岸的博客-CSDN博客

Table | Semantic UI 官网

相关推荐
南宫生2 小时前
力扣每日一题【算法学习day.132】
java·学习·算法·leetcode
计算机毕设定制辅导-无忧学长2 小时前
Maven 基础环境搭建与配置(一)
java·maven
bing_1582 小时前
简单工厂模式 (Simple Factory Pattern) 在Spring Boot 中的应用
spring boot·后端·简单工厂模式
天上掉下来个程小白3 小时前
案例-14.文件上传-简介
数据库·spring boot·后端·mybatis·状态模式
风与沙的较量丶3 小时前
Java中的局部变量和成员变量在内存中的位置
java·开发语言
m0_748251723 小时前
SpringBoot3 升级介绍
java
极客先躯4 小时前
说说高级java每日一道面试题-2025年2月13日-数据库篇-请说说 MySQL 数据库的锁 ?
java·数据库·mysql·数据库的锁·模式分·粒度分·属性分
程序员侠客行4 小时前
Spring事务原理 二
java·后端·spring
小猫猫猫◍˃ᵕ˂◍5 小时前
备忘录模式:快速恢复原始数据
android·java·备忘录模式
liuyuzhongcc5 小时前
List 接口中的 sort 和 forEach 方法
java·数据结构·python·list