SpringBoot企业微信点餐实践分享-免费源码
2018-10-23 本文已影响2人
织梦少年666
Springboot+mybatis+pagehelper+freemarker动态分页功能-可以直接使用
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
#DAO
List<UserDto> queryBackUser();
#Service
PageInfo<UserDto> queryBackUser(int page, int size);
#ServiceImpl
@Override
public PageInfo<UserDto> queryBackUser(int page,int size) {
PageHelper.startPage(page, size);//改写语句实现分页查询
List<UserDto> users = userDao.queryBackUser();
PageInfo<UserDto> info = new PageInfo<>(users);
return info;
}
#Controller
@GetMapping("/list")
public ModelAndView list(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "size", defaultValue = "20") Integer size,Map<String, Object> map){
PageInfo<UserDto> userList = userService.queryBackUser(page,size);
map.put("userList",userList);
map.put("currentPage", page);
map.put("size", size);
return new ModelAndView("user/list",map);
}
<#--动态分页-->
<div class="col-md-12 column">
<ul class="pagination pull-right">
<#if currentPage lte 1>
<li class="disabled"><a href="#">上一页</a></li>
<#else>
<li><a href="/back/user/list?page=${currentPage - 1}&size=${size}">上一页</a></li>
</#if>
<#--第一页-->
<#if (userList.pages > 0)>
<li <#if currentPage == 1>class="disabled"</#if>><a href="/back/user/list?page=1&size=${size}" >1</a></li>
</#if>
<#--如果不只有一页-->
<#if (userList.pages > 1)>
<#--如果当前页往前查3页不是第2页-->
<#if ((currentPage - 3) > 2)>
<li><span class="text">…</span></li>
</#if>
<#--当前页的前3页和后3页-->
<#list (currentPage - 3)..(currentPage + 3) as index>
<#--如果位于第一页和最后一页之间-->
<#if (index > 1) && (index < userList.pages)>
<li <#if currentPage == index>class="disabled"</#if>><a href="/back/user/list?page=${index}&size=${size}" >${index}</a></li>
</#if>
</#list>
<#--如果当前页往后查3页不是倒数第2页-->
<#if (currentPage + 3) < (userList.pages - 1)>
<li><span class="text">…</span></li>
</#if>
<#--最后页-->
<li <#if currentPage == userList.pages>class="disabled"</#if>><a href="/back/user/list?page=${userList.pages}&size=${size}" >${userList.pages}</a></li>
</#if>
<#if currentPage gte userList.pages>
<li class="disabled"><a href="#">下一页</a></li>
<#else>
<li><a href="/back/user/list?page=${currentPage + 1}&size=${size}">下一页</a></li>
</#if>
</ul>
</div>
image.png
资源链接
链接: https://pan.baidu.com/s/1Gp3huNRyetAiXmwG1tF36A 提取码: vks3