最近打算使用freemarker完成一个论坛系统,在发帖功能中需要使用到freemarker的分页,网上看了好多,都不是我想要的那种,而且和我已经完成的东西有很大出入,没有办法,自己动手,丰衣足食,so,请看ftl文件
<div id="forum_pagination" class="forum_pagination"> <div class="forum_pagination_page"> <#if page??> <span class="myspan007">${page.currentPage}/${page.pageCount}</span> <a class="mya001" href="${projectIp+page.pageUrl}1.html">首页</a> <#if ((page.pageCount) <= 11) > <#list 1..(page.pageCount) as index_page> <#if (page.currentPage) == index_page > <a class="mya001 mya004" href="${projectIp+page.pageUrl}${index_page}.html">${index_page}</a> <#else> <a class="mya001" href="${projectIp+page.pageUrl}${index_page}.html">${index_page}</a> </#if> </#list> <#elseif ((page.pageCount) > 11)> <#if (((page.currentPage)+5) > (page.pageCount))> <#list (10-page.pageCount+page.currentPage)..1 as index_page> <a class="mya001" href="${projectIp+page.pageUrl}${page.currentPage - index_page}.html">${page.currentPage - index_page}</a> </#list> <a class="mya001 mya004" href="${projectIp+page.pageUrl}${page.currentPage}.html">${page.currentPage}</a> <#if ((page.pageCount-page.currentPage) > 0)> <#list 1..(page.pageCount-page.currentPage) as index_page> <a class="mya001" href="${projectIp+page.pageUrl}${page.currentPage + index_page}.html">${page.currentPage + index_page}</a> </#list> </#if> <#elseif (((page.currentPage)-5) > 1)> <#list 5..1 as index_page> <a class="mya001" href="${projectIp+page.pageUrl}${page.currentPage - index_page}.html">${page.currentPage - index_page}</a> </#list> <a class="mya001 mya004" href="${projectIp+page.pageUrl}${page.currentPage}.html">${page.currentPage}</a> <#list 1..5 as index_page> <#if ((page.currentPage) + index_page <= (page.pageCount))> <a class="mya001" href="${projectIp+page.pageUrl}${page.currentPage + index_page}.html">${page.currentPage + index_page}</a> </#if> </#list> <#else> <#list 1..11 as index_page> <#if (page.currentPage) == index_page> <a class="mya001 mya004" href="${projectIp+page.pageUrl}${page.currentPage}.html">${page.currentPage}</a> <#else> <a class="mya001" href="${projectIp+page.pageUrl}${index_page}.html">${index_page}</a> </#if> </#list> </#if> </#if> <a class="mya001" href="${projectIp+page.pageUrl+page.pageCount}.html">末页</a> </#if> </div> </div>
该ftl主要对分页的逻辑做了处理,具体如何使用,请参考《freemarker里的分页--ftl文件的传值》
时间: 2025-01-14 07:39:52