一段freemarker高级分页效果的代码

时间:2022-09-04 08:21:26

<a onclick="page(1)">首页</a>
[#if currpage != 1]
[#assign last=currpage - 1]
<a onclick="page('${last}')">上一页</a>
[/#if]
[#assign pages=count/10 ]
[#if pages <= 10]
[#list 1..pages as p]
[#if p == currpage]
<span>${p}</span>
[#else]
<a onclick="page('${p}')")">${p}</a>
[/#if]
[/#list]
[#else]
[#if currpage <= 4]
[#list 1..5 as p]
[#if p == currpage]
<span>${p}</span>
[#else]
<a onclick="page('${p}')">${p}</a>
[/#if]
[/#list]
....
[#list (pages-4)..pages as p]
<a onclick="page('${p}')">${p}</a>
[/#list]
[#elseif (pages-currpage) <= 3]
[#list 1..5 as p]
<a onclick="page('${p}')">${p}</a>
[/#list]
....
[#list (pages-4)..pages as p]
[#if p == currpage]
<span>${p}</span>
[#else]
<a onclick="page('${p}')">${p}</a>
[/#if]
[/#list]
[#else]
<a onclick="page(1)">1</a>
...
[#assign lll=currpage-3]
<a onclick="page('${lll}')">${lll}</a>
[#assign ll=currpage-2]
<a onclick="page('${ll}')">${ll}</a>
[#assign l=currpage-1]
<a onclick="page('${l}')">${l}</a>
<span>${currpage}</span>
[#assign n=currpage+1]
<a onclick="page('${n}')">${n}</a>
[#assign nn=currpage+2]
<a onclick="page('${nn}')">${nn}</a>
[#assign nnn=currpage+3]
<a onclick="page('${nnn}')">${nnn}</a>
...
<a onclick="page('${pages}')">${pages}</a>
[/#if]
[/#if]
[#if currpage != pages]
[#assign next = currpage+1]
<a onclick="page('${next}')">下一页</a>
[/#if]
<a onclick="page('${pages}')">末页</a>