栏目分页查询数据

默认情况栏目会自动查询出分页数据,模板界面只需要配置好分页样式即可

    <!--#include file="page.html"-->
    <@paginate currentPage=page.currentPageNo totalPage=page.totalPages />

分页宏如下:

<#macro paginate currentPage totalPage >
    <#if (totalPage <= 0) || (currentPage > totalPage)><#return></#if>
    <#local startPage = currentPage - 4>
    <#if (startPage < 1)><#local startPage = 1></#if>
    <#local endPage = currentPage + 4>
    <#if (endPage > totalPage)><#local endPage = totalPage></#if>
    <div class="page" style=" margin-right:5px;">
        <span></span>
        <#if (currentPage <= 8)>
            <#local startPage = 1>
        </#if>
        <#if ((totalPage - currentPage) < 8)>
            <#local endPage = totalPage>
        </#if>

        <#if (currentPage == 1)>
                <a class="btn prev" style="disabled:true;">上一页</a>
            <#else>
                <#if currentPage == 2>
                    <#local prevPageUrl = "/cms?p=" + p>
                    <a class="btn prev" href="${url}${encoder(prevPageUrl)}">上一页</a>
                <#else>
                    <#local prevPageUrl = "/cms?p=" + p + "&page=" + (currentPage - 1) >
                    <a class="btn prev" href="${url}${encoder(prevPageUrl)}">上一页</a>
                </#if>
        </#if>

        <#if (currentPage > 8)>
            <a class="btn " href="#">#{1}</a>
            <a class="btn " href="#">#{2}</a>
            <span class="gap">…</span>
        </#if>

        <#list startPage..endPage as i>
            <#if currentPage == i>
                    <a class="active">#{i}</a>
                <#else>
                    <#if i == 1>
                        <#local prevPageUrl = "/cms?p=" + p><a class="btn " href="${url!}${encoder(prevPageUrl)}">1</a>
                    <#else>

                        <#local currentPageUrl = "/cms?p=" + p + "&page=" + i ><a class="btn " href="${url!}${encoder(currentPageUrl)}">#{i}</a>

                    </#if>
            </#if>
        </#list>

        <#if ((totalPage - currentPage) >= 8)>
            <span class="gap">…</span>
            <a class="btn " href="#">#{totalPage - 1}</a>
            <a class="btn " href="#">#{totalPage}</a>
        </#if>

        <#if (currentPage == totalPage)>
            <a class="btn next" style="disabled:true;">下一页</a>
            <#else>
                <#local nextPageUrl = "/cms?p=" + p + "&page=" + (currentPage + 1) >
                    <a class="btn next" href="${url}${encoder(nextPageUrl)}">下一页</a>
        </#if>
    </div>
    <div style="clear:both;"></div>
</#macro>

results matching ""

    No results matching ""