controller:

/**
 * 分页查询用户
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value="/queryList",method=RequestMethod.GET)
public String query(HttpServletRequest request,
HttpServletResponse response, 
@RequestParam(defaultValue = "1") Integer pageNum, 
@RequestParam(defaultValue = "5") Integer pageSize) throws Exception{
PageHelper.startPage(pageNum, pageSize);
List<SecUser> list =service.queryByList();
PageInfo<SecUser> pageInfo = new PageInfo<SecUser>(list);

//获得当前页
request.setAttribute("pageNum", pageInfo.getPageNum());
        //获得一页显示的条数
request.setAttribute("pageSize", pageInfo.getPageSize());
        //是否是第一页
request.setAttribute("isFirstPage", pageInfo.isIsFirstPage());
        //获得总页数
request.setAttribute("totalPages", pageInfo.getPages());
        //是否是最后一页
request.setAttribute("isLastPage", pageInfo.isIsLastPage());
//所有导航页号
request.setAttribute("naviPageNums", pageInfo.getNavigatepageNums());

request.setAttribute("list", list);
return "user/list";
}

service:

public List<SecUser> queryByList(){
return dao.queryByList();
}

dao:

public List<SecUser> queryByList();

mapper:

<select id="queryByList" resultMap="userMap" >
select 
id,
<include refid="requiredColumn" />
from 
userbase
where 
1=1
</select>

页面:

<div>
            <ul class="pagination">
                <!-- <li><a href="">&laquo;</a></li> -->
                <li>
                    <a  th:href="@{${'/user/queryList'}(pageNum=1,pageSize=${pageSize})}">首页</a>
                </li>

<li>
                    <a th:if="${not isFirstPage}" th:href="@{${'/user/queryList'}(pageNum=${pageNum-1},pageSize=${pageSize})}">上一页</a>
                    <a th:if="${isFirstPage}" href="javascript:void(0);">上一页</a>
                </li>

<li th:each="pageNo : ${naviPageNums}">
                    <a th:if="${pageNum eq pageNo}" href="javascript:void(0);">
                         <span th:text="${pageNo}"></span>
                    </a>

<a th:if="${not (pageNum eq pageNo)}" th:href="@{${'/user/queryList'}(pageNum=${pageNo},pageSize=${pageSize})}">
                        <span th:text="${pageNo}"></span>
                    </a>
                </li>
                <li>
                        <a th:if="${not isLastPage}" th:href="@{${'/user/queryList'}(pageNum=${pageNum+1},pageSize=${pageSize})}">下一页</a>
                        <a th:if="${isLastPage}" href="javascript:void(0);">下一页</a>
                 </li>
                 
                 <li>
                        <a  th:href="@{${'/user/queryList'}(pageNum=${totalPages},pageSize=${pageSize})}">尾页</a>
                 </li>

<!-- <li><a href="#">&raquo;</a></li> -->
            </ul>
        </div>

spring boot +Thymeleaf+mybatis 集成通用PageHelper,做分页的更多相关文章

  1. Spring boot+Thymeleaf+easyui集成:js创建组件页面报错

    开发工具:Ideal 使用场景:Demo 前提:       环境:Spring boot +Thymeleaf+easyui 引入thymeleaf模板引擎 <html lang=" ...

  2. spring boot 和 mybatis集成

    1.pom.xml 添加mybatis和mysql依赖 <!-- 添加 MyBatis --> <dependency> <groupId>org.mybatis. ...

  3. Spring boot 配置 mybatis xml和动态SQL 分页配置

    更新时间 2018年4月30日23:27:07 1.pom.xml <?xml version="1.0" encoding="UTF-8"?> & ...

  4. spring boot 1.4.2.RELEASE+Thymeleaf+mybatis 集成通用maper,与分页插件:

    <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...

  5. spring boot和mybatis集成分页插件

    MyBatis提供了拦截器接口,我们可以实现自己的拦截器,将其作为一个plugin装入到SqlSessionFactory中. 首先要说的是,Spring在依赖注入bean的时候,会把所有实现MyBa ...

  6. spring boot集成mybatis(2) - 使用pagehelper实现分页

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  7. Spring Boot 数据访问集成 MyBatis 与事物配置

    对于软件系统而言,持久化数据到数据库是至关重要的一部分.在 Java 领域,有很多的实现了数据持久化层的工具和框架(ORM).ORM 框架的本质是简化编程中操作数据库的繁琐性,比如可以根据对象生成 S ...

  8. 9、Spring Boot 2.x 集成 Thymeleaf

    1.9 Spring Boot 2.x 集成 Thymeleaf 完整源码: Spring-Boot-Demos 1.9.1 在pom中引入依赖 <dependency> <grou ...

  9. 6、Spring Boot 2.x 集成 MyBatis

    1.6 Spring Boot 2.x 集成 MyBatis 简介 详细介绍如何在Spring Boot中整合MyBatis,并通过注解方式实现映射. 完整源码: 1.6.1 创建 spring-bo ...

随机推荐

  1. java线程面试题及答案

    1)2017Java面试题及答案:什么是线程? 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位.程序员可以通过它进行多处理器编程,你可以使用多线程对运算密集型任务 ...

  2. 云服务利用Auto Scaling节省30%成本

    公有云提供了很多免费的高级功能,很多中小用户以为自己用不上.实际上稍微研究一下,就能享受很多便利和节省不少成本. 本方案就是利用弹性伸缩(auto-scaling)减少服务器成本,几乎适合所有集群式部 ...

  3. Javascript面向对象(三):非构造函数的继承

    这个系列的第一部分介绍了"封装",第二部分介绍了使用构造函数实现"继承". 今天是最后一个部分,介绍不使用构造函数实现"继承". 一.什么是 ...

  4. ssh整合(dao使用hibernateTemplate)

  5. 一篇docker的详细技术文章

    http://www.open-open.com/lib/view/open1423703640748.html

  6. C语言-郝斌笔记-005菲波拉契序列

    菲波拉契序列 /* 菲波拉契序列 1 2 3 5 8 13 21 34 */ # include <stdio.h> int main(void) { int n; int f1, f2, ...

  7. 前端基础 之 jQuery

    浏览目录 jQuery介绍 jQuery的优势 jQuery对象 jQuery内容 一.jQuery介绍 1.jQuery是一个轻量级的.兼容多浏览器的JavaScript库. 2.jQuery使用户 ...

  8. dfs和bfs算法

    1. 存储图的方式一般是有两种的:邻接表和邻接矩阵,一般存储链接矩阵的方式是比较简单的,也便于我们去实现这个临接矩阵,他也就是通俗的二维数组,我们平常用到的那种. 2. 这里我们主要记录和讲一下bfs ...

  9. ModelSim Simulation of RapidIO II IP Core Demonstration Testbench May Require ld_debug Command

    Solution ID: fb83262Last Modified: May 17, 2013Product Category: Intellectual PropertyProduct Area: ...

  10. 在WindowsXP+IIS5.1下运行ASP.NET MVC3

    1. 安装ASP.NET MVC3 http://download.microsoft.com/download/1/4/C/14C0533D-2299-42CD-898C-10AA5156E243/ ...