传值:
pages(总页数)和currentpage(当前页)
分页代码:(freemarke)
引用处:
<div style=" text-align: center;">
<#include "../layout/_pagelist.html">
</div>
控制层:
// 分页实现
// 查总条数
int size = this.productService.countBaseinfo();
int currentpage = currentPage !=null?currentPage:1;
int pagesize = pageSize !=null?pageSize:10;
int pages = (int) Math.ceil((float)size/pagesize);
// 分页查询
Page<ProductBaseInfo> productBaseinfos = productService.selectBaseinfo(currentpage,pagesize);
mv.addObject("currentpage", currentpage);
mv.addObject("pages", pages);
service层 new PageRequest()方法
Page<ProductBaseInfo> list = productBaseinfoRepository.findAll(new PageRequest(currentPage-1, pageSize));
组件文件:
<!--分页组件-->
<ul class="pagination">
<#if currentpage==1>
<#else>
<li><a href="/Kweb/admin/getBaseinfo?currentPage=${currentpage-1}">«</a></li>
</#if>
<!-- 总页数小于5循环遍历 -->
<#if pages! lt 6>
<#list 1..pages as i>
<#if i==currentpage>
<li class="active"><a href="//Kweb/admin/getBaseinfo?currentPage=${i}">${i}</a></li>
<#else>
<li class=""><a href="/Kweb/admin/getBaseinfo?currentPage=${i}">${i}</a></li>
</#if>
</#list>
</#if>
<!-- 总页数大于5 -->
<#if pages! gt 5>
<#if currentpage+4 lt pages>
<#list currentpage.. currentpage+4 as i>
<#if i==currentpage>
<li class="active"><a href="/Kweb/admin/getBaseinfo?currentPage=${i}">${i}</a></li>
<#else>
<li class=""><a href="/Kweb/admin/getBaseinfo?currentPage=${i}">${i}</a></li>
</#if>
</#list>
<#else>
<#list pages-4..pages as i>
<#if i==currentpage>
<li class="active"><a href="/Kweb/admin/getBaseinfo?currentPage=${i}">${i}</a></li>
<#else>
<li class=""><a href="/Kweb/admin/getBaseinfo?currentPage=${i}">${i}</a></li>
</#if>
</#list>
</#if>
</#if>
<#if pages==currentpage>
<#else>
<li>
<a href="/Kweb/admin/getBaseinfo?currentPage=${currentpage+1}">»</a>
</li>
</#if>
</ul>
网友评论