freemarker 分页逻辑

<#-- 
 分页组件
    需要传入的参数 pageUrl ,用来生成的html地址,在pageUrl中必须有{page}在生成html地址的时候会自动把页码给赋值上去。页码起始值为1
    @pageNum 最大显示页 默认9
    @beforPage 前显示页 默认3
    @afterPage  后显示页 默认3
    @countPage 总页数   必须传入
    @currentPage 当前页 必须传入
    @currentPageClass 选中页码传递的样式,实现为直接将值贴给元素 <a href="#" ${currentPageClass}>
    @pageUrl  请求地址模板 ,内容中必须含有{page}用来替换页码
 -->
<#assign pageNum = pageNum!9>
<#assign beforPage = beforPage!3>
<#assign afterPage = afterPage!3>
<#assign countPage =countPage!page.countPageNumber>
<#assign currentPage = currentPage!page.currentNumber>
<#assign currentPageClass = currentPageClass!"class='thispage'">
<#assign pageUrl = pageUrl>
<#-- 分页地址 -->
<#function getPageUrl page>
 <#return pageUrl?replace('{page}',page)>
</#function>


<#if (countPage > 1)>
 <#if currentPage != 1>
 <a class="nextpage m_l15" href="${getPageUrl(currentPage - 1)}">上一页</a>
 </#if>
       
 <#if (countPage > pageNum)><#-- 总页数大于最大显示页 -->
 <#if (pageNum > currentPage)><#-- 当前页小于显示页 -->
 <#list 1..pageNum as index>
 <a href="${getPageUrl(index)}"  <#if currentPage == index>${currentPageClass}</#if>>${index}</a>
 </#list>
 <#else>
 <a href="${getPageUrl(1)}">1</a>...
 <#list currentPage-beforPage..currentPage + afterPage as index>
 <#if (index > 0) && (index < countPage)>
 <a href="${getPageUrl(index)}"  <#if currentPage == index>${currentPageClass}</#if>>${index}</a>
 </#if>
 </#list>
 </#if> 
 <#if (currentPage < countPage - afterPage)>...</#if>
 <a href="${getPageUrl(countPage)}" <#if currentPage == countPage>${currentPageClass}</#if>>${countPage}</a>
 <#else><#-- 总页数小于显示页 -->
 <#list 1..countPage as index>
 <a href="${getPageUrl(index)}"  <#if currentPage == index>${currentPageClass}</#if>>${index}</a>
 </#list>
 </#if>
 <#if countPage != currentPage>
 <a class="nextpage" href="${getPageUrl(currentPage + 1)}">下一页</a>
 </#if>
</#if>

转载于:https://my.oschina.net/wjgood/blog/97489

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值