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 ...
随机推荐
- Eclipse中Next Difference的快捷键
原文:http://stackoverflow.com/questions/10177460/is-there-a-key-binding-for-next-difference-and-previo ...
- activity状态保存的bundl对象存放位置的思考
我们知道,当activity被异常终止时,可以把一些信息保存到bundle对象中,在下次启动时恢复. 那么,这个bundle对象是保存在哪里的呢? 这种状态保存的方法针对的是activity而不是进程 ...
- Arduino Uno 在win7 64位下的驱动问题
1.解压[mdmcpq.inf_amd64_neutral_fbc4a14a6a13d0c8.rar],将[mdmcpq.inf_amd64_neutral_fbc4a14a6a13d0c8]文件夹复 ...
- 【总结整理】WebGIS学习-thinkGIS(二):关于level,比例尺scale,分辨率resolution
1.Level包含了一个resolution参数和一个scale参数 瓦片本身: 我们用arcgis切完图后,打开发布的服务或者打开config.xml配置文件,可以看到所切之图的相关配置.如图所示: ...
- 【安装关键】webStorm-201703版本
在激活页面选择License Server,输入:http://idea.codebeta.cn,点击Activate即可激活.
- Codeforces 1137C Museums Tour (强连通分量, DP)
题意和思路看这篇博客就行了:https://www.cnblogs.com/cjyyb/p/10507937.html 有个问题需要注意:对于每个scc,只需要考虑进入这个scc的时间即可,其实和从哪 ...
- Action层, Service层 和 Dao层的功能区分
Action/Service/DAO简介: Action是管理业务(Service)调度和管理跳转的. Service是管理具体的功能的. Action只负责管理,而Service负责实施. DAO ...
- c#与Java事件定义的不同
C#: using System; using System.Collections.Generic; using System.Text; namespace Test1 { class Progr ...
- Win32编程中如何处理控制台消息
这篇文章讨论如何处理所有的控制台消息. 第一步,首先要安装一个事件钩子,也就是说要建立一个回调函数.调用Win32 API,原型如下: BOOL SetConsoleCtrlHandler(PHAND ...
- 用C++实现void reverse(char* str)函数,即反转一个null结尾的字符串.
void reverse(char* str) { char *end = str, *begin=str; char temp; while(*end!='\0') { end++; } end-- ...