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>