当前位置: 代码迷 >> Web前端 >> 利用freemarker 授命分页(宏,assign等)
  详细解决方案

利用freemarker 授命分页(宏,assign等)

热度:77   发布时间:2012-10-30 16:13:36.0
利用freemarker 指令分页(宏,assign等)

freemarker分页,首先在web.xml中做好配置(这里说的配置就是让web过滤我们的freemarker指令)。

下面是代码:

<#assign currentPage=(RequestParameters["currentPage"]?number)!1>//传入的当前页,如果没有传入,默认就是第一页。
				<#assign count=reply.count>//这里的reply.count是程序中用到的一个参数,也是从其他页面传过来的“总记录数”。
				<#assign next=(currentPage+1)>
				<#assign last=(currentPage-1)>
				<#if count%10==0>
				<#assign page=count/10>
				<#else>
				<#assign page=(count/10)?int+1>
				</#if>
				<#if (currentPage-3>1)>
				<#assign first=(currentPage-3)>
				<#else>
				<#assign first=1>
				</#if>
				<#if ((currentPage+3)>page) >
				<#assign end=page>
				<#else>
				<#assign end=(currentPage+3)>
				</#if>
				<#assign f=first>
				<#macro loop>
				<#if (f>end) >
				<#else>
				<#if currentPage==f>
				<span class=tP>${f}&nbsp;</span>
                <#else>
				<a href="replylist.html?msgid=${msgid}&currentPage=${f}">${f}</a>&nbsp;//分页的页面。
			    </#if>
			    <#assign f=f+1>
			    <@loop />
			    </#if>
				</#macro>
			  <#macro firstP>
			  <#if currentPage!=1>
			  <a href="replylist.html?msgid=${msgid}&currentPage=1">首页</a><a href="replylist.html?msgid=${msgid}&currentPage=${last}">上一页</a>
			  </#if>
			  </#macro>
			  <#macro endP>
			  <#if currentPage!=page>
			  <a href="replylist.html?msgid=${msgid}&currentPage=${next}">下一页</a><a href="replylist.html?msgid=${msgid}&currentPage=${page}">尾页</a>
			  </#if>
			  </#macro>//宏定义结束
			  <@firstP /><@loop /><@endP />//循环

?