freemarker模板引擎自定義分頁

需求:需要把原有的vue頁面改成靜態(tài)化頁面,前端給了靜態(tài)化模板,直接復(fù)制至ftl模板文件中,具體動態(tài)的參數(shù)重新從后臺拿值渲染。

Java代碼:

//頁碼

int pageIndex;

int pageIndex1;

//每頁數(shù)量

int pageSize =9;

//總條數(shù)

int total? =iSysExhibitionService.selectSysExhibitionsListCount(new SysExhibition());

// 向上取整

int num = (int)Math.ceil(((double)total/pageSize));

//有多少頁生成多少個html

for (int i=1;i<=num;i++){

System.out.println(i);

? ? pageIndex=i;

? ? pageIndex1=i;

? ? int pageIndexNum = --pageIndex;

? ? List list =iSysExhibitionService.selectSysExhibitionsList2(new SysExhibition(){{

setPageIndex(pageIndexNum *pageSize);

? ? ? ? setPageSize(pageSize);

? ? }});

? ? int finalPageIndex = pageIndex1;

? ? Map map1 =new HashMap(){{

put("list", list);

? ? ? ? put("currentPage", finalPageIndex);//當(dāng)前頁

? ? ? ? put("totalPage", num);//總頁數(shù)

? ? ? ? put("actionUrl", config.getPath());//首頁地址

? ? ? ? put("detailPath", config.getDetailPath());//詳情地址

? ? }};

? ? freemarkerUtil.generate(config.getUrl(),"index.ftl", "index"+i, map1);

}

ftl模板代碼:

currentPage :當(dāng)前頁

totalPage:總頁數(shù)

actionUrl:分頁html存放地址

<#-- 上一頁按鈕-->

<#if (currentPage >1)>

? ? <a class="pg-prev" href="${actionUrl}${currentPage -1}.html" page-id="${currentPage -1}">

<#else>

? ? <a class="pg-prev" page-id="0">

</#if>

<#-- 第一頁按鈕-->

<#if 1 == currentPage>

? ? <span class="current" page-id="1">1

<#else>

? ? <a href="${actionUrl}1.html" page-id="1">1

</#if>

<#--中間頁數(shù)-->

<#if (totalPage<7)>

? ? <#if ((totalPage -1)>=2)>

? ? ? ? <#list 2..(totalPage -1)as i>

? ? ? ? ? ? <#if currentPage == i>

? ? ? ? ? ? ? ? <span class="current" href="${actionUrl}${i}.html" page-id="${i}">${i}

? ? ? ? ? ? <#else>

? ? ? ? ? ? ? ? <a href="${actionUrl}${i}.html" page-id="${i}">${i}

? ??????????</#if>

? ??????</#list>

? ??</#if>

<#else>

? ? <#if (currentPage <6)>

? ? ? ? <#list 2..5 as i>

? ? ? ? ? ? <#if currentPage == i>

? ? ? ? ? ? ? ? <span class="current" href="${actionUrl}${i}.html" page-id="${i}">${i}

? ? ? ? ? ? <#else>

? ? ? ? ? ? ? ? <a href="${actionUrl}${i}.html" page-id="${i}">${i}

? ??????????</#if>

? ??????</#list>

? ? ? ? <#if ((currentPage +2) <= totalPage)>

? ? ? ? ? ? <a>...</a>

????????</#if>

<#else>

? ? ? ? <#if ((totalPage - currentPage) <5)>

? ? ? ? ? ? <#if ((totalPage -4) >2)>

? ? ? ? ? ? ? ? <a>...</a>

????????????</#if>

? ? ? ? ? ? <#list (totalPage -4)..(totalPage -1)as i>

? ? ? ? ? ? ? ? <#if currentPage == i>

? ? ? ? ? ? ? ? ? ? <span class="current" href="${actionUrl}${i}.html" page-id="${i}">${i}

? ? ? ? ? ? ? ? <#else>

? ? ? ? ? ? ? ? ? ? <a href="${actionUrl}${i}.html" page-id="${i}">${i}

? ??????????????</#if>

? ??????????</#list>

<#else>

? ? ? ? ? ?<a>...</a>

? ? ? ? ? ? <#list (currentPage -2)..(currentPage +2)as i>

? ? ? ? ? ? ? ? <#if currentPage == i>

? ? ? ? ? ? ? ? ? ? <span class="current" href="${actionUrl}${i}.html" page-id="${i}">${i}

? ? ? ? ? ? ? ? <#else>

? ? ? ? ? ? ? ? ? ? <a href="${actionUrl}${i}.html" page-id="${i}">${i}

????????????????</#if>

? ??????????</#list>

? ? ? ? ? ? <a>...</a>

? ??????</#if>

? ??</#if>

</#if>

<#-- 最后一頁按鈕-->

<#if (totalPage >1)>

? ? <#if totalPage? == currentPage>

? ? ? ? <span class="current" page-id="${totalPage}">${totalPage}

? ? <#else>

? ? ? ? <a href="${actionUrl}${totalPage}.html" page-id="${totalPage}">${totalPage}

? ??</#if>

</#if>

<#-- 下一頁按鈕-->

<#if (currentPage +1 > totalPage)>

? ? <a class="pg-next" page-id="${totalPage}">

<#else>

? ? <a class="pg-next" href="${actionUrl}${currentPage +1}.html" page-id="${currentPage +1}">

</#if>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容