spring boot +Thymeleaf+mybatis 集成通用PageHelper,做分页
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="">«</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="#">»</a></li> -->
</ul>
</div>
spring boot +Thymeleaf+mybatis 集成通用PageHelper,做分页的更多相关文章
- Spring boot+Thymeleaf+easyui集成:js创建组件页面报错
开发工具:Ideal 使用场景:Demo 前提: 环境:Spring boot +Thymeleaf+easyui 引入thymeleaf模板引擎 <html lang=" ...
- spring boot 和 mybatis集成
1.pom.xml 添加mybatis和mysql依赖 <!-- 添加 MyBatis --> <dependency> <groupId>org.mybatis. ...
- Spring boot 配置 mybatis xml和动态SQL 分页配置
更新时间 2018年4月30日23:27:07 1.pom.xml <?xml version="1.0" encoding="UTF-8"?> & ...
- spring boot 1.4.2.RELEASE+Thymeleaf+mybatis 集成通用maper,与分页插件:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...
- spring boot和mybatis集成分页插件
MyBatis提供了拦截器接口,我们可以实现自己的拦截器,将其作为一个plugin装入到SqlSessionFactory中. 首先要说的是,Spring在依赖注入bean的时候,会把所有实现MyBa ...
- spring boot集成mybatis(2) - 使用pagehelper实现分页
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- Spring Boot 数据访问集成 MyBatis 与事物配置
对于软件系统而言,持久化数据到数据库是至关重要的一部分.在 Java 领域,有很多的实现了数据持久化层的工具和框架(ORM).ORM 框架的本质是简化编程中操作数据库的繁琐性,比如可以根据对象生成 S ...
- 9、Spring Boot 2.x 集成 Thymeleaf
1.9 Spring Boot 2.x 集成 Thymeleaf 完整源码: Spring-Boot-Demos 1.9.1 在pom中引入依赖 <dependency> <grou ...
- 6、Spring Boot 2.x 集成 MyBatis
1.6 Spring Boot 2.x 集成 MyBatis 简介 详细介绍如何在Spring Boot中整合MyBatis,并通过注解方式实现映射. 完整源码: 1.6.1 创建 spring-bo ...
随机推荐
- CSS——position
position是指元素的定位方式,有:static.absolute.fixed.relative.inherit 5种. static 默认,布局排版方式按照HTML代码的顺序布局. absolu ...
- ImageView 的 ScaleType
/** * Options for scaling the bounds of an image to the bounds of this view. 将一个图片的边界缩放到这个view边界的几种选 ...
- 跨域Ajax原理以及浏览器同源策略
- CodeForces 1109C. Sasha and a Patient Friend
题目简述:维护以下三种操作 1. "1 t s":在时刻$t$插入命令$s$.保证任意操作后,任意时刻至多只有一个命令. 2. "2 t":删除时刻$t$的命令 ...
- CMake 默认编译、链接选项
查看cmake默认编译和链接的参数设置 CMakeLists.txt 文件内容: cmake_minimum_required(VERSION 3.2) message(STATUS "CM ...
- hdu6357 Hills And Valleys
传送门 题目大意 给定一个序列A,求翻转A中一个区间之后的最长不降子序列的长度即翻转的区间 分析 发现直接枚举翻转的区间的话是无论如何都不行的,于是有一个非常神奇的做法.我们再设一个序列B = {0, ...
- Luogu 3676 小清新数据结构题
推荐博客: http://www.cnblogs.com/Mychael/p/9257242.html 感觉还挺好玩的 首先考虑以1为根,把每一个点子树的权值和都算出来,记为$val_{i}$,那么在 ...
- Git 之 github分享代码
作为一个技术人员还是脱离不了屌丝的本质,所以每天都是逛逛github,看看别人有什么好的项目,自己可以给他挑挑bug也可以提供自己的水平,但是别人不那怎么才能给别人贡献代码呢?那就是fork了.... ...
- kaggle Cross-Validation
The Cross-Validation Procedure In cross-validation, we run our modeling process on different subsets ...
- Fast Scatter-Gather I/O
Some applications may need to read or write data to multiple buffers, which are separated in memory. ...