[#--pagination Idea 1 each page shows a fixed number of pages as far as possible to keep the current page in the central part of the display 1. if the current page number is less than or equal to half of the page to display The following algorithm calculates the display if the total number of pages is less than or equal to the number of pages to display from the first page to the total number of pages (last page) if the total number of pages is greater than the number of pages to display the page to display from the first page 2. if the current page number is greater than half the page to display, The following algorithm is calculated to show if the total number of pages is less than or equal to (the current page + page to display half of the pages) from (the current page number-half of the pages to display) display to total pages if the total number of pages is greater than (the current page + half of the pages to be displayed) from (current page number-half of the pages to display) display to (half of the number of pages currently on the page + page to display)--][#macro pager url totalpage curpage=1 class= "" showpagenum=5][#local halfpage= ( SHOWPAGENUM/2)? int/][@showFirstPage url=url class=class curpage=1 /][#if (curpage > 1)] [@showPrePage url=url class=class curpage=curpage-1 /][/#if] [#if ( Halfpage>=curpage)] [#if (Showpagenum >= totalpage)] [@showPage start=1 end= totalpage url=url class=class curpage=curpage/][#else] [@showPage start=1 end= Showpagenum url=url class=class curpage=curpage /][/#if] [#else] [#if (Curpage+halfpage>totalpage)] [@showPage start= (Curpage-halfpage) end=totalpage url=url class=class curpage=curpage/][#else] [@showPage start= ( Curpage-halfpage) end=curpage+halfpage url=url class=class curpage=curpage/][/#if][/#if][# if (Totalpage > curpage)] [@showNextPage url=url class=class curpage= (curPage+ 1) /][/#if] [@showLastPage url=url class=class curpage=totalpage /] Total [${totalpage}] page [/# macro][#macro showpage start end url class curpage][#list start. end as page][#if curpage==page][${page}][#else]<a href= "${url}&pageindex=${page}" class= "${class}" >${page}</a>[/#if][/#list][/#macro][#--Display Home--][#macro showFirstPage url class curpage]<a href= "${url}&pageindex=${curpage}" class= "${class}" > Home </ a>[/#macro][#--Display previous page--][#macro showprepage url class curpage]<a href= "${url}&pageindex=${curpage}" class= "${class}" > previous page </a>[/#macro][#--Show next--][#macro shownextpage url class curpage]<a href= "${url}&pageindex=${curpage}" class= "${class}" > Next </a>[/#macro ][#--display last--][#macro showlastpage url class curpage]<a href= "${url}&pageIndex=$ {curpage} " class=" ${class} "> Last </a>[/#macro][#--------------------------------------------------- ------------------------------------------][#--Pagination Idea 2 Each page shows a fixed number of pages try to keep the current page in the center of the display 1. if the total number of pages is equal to the number of pages to display from the first page to the total number of pages (last page) 2. if the total number of pages is greater than the number of pages to display then follow the algorithm display if the current page is less than or equal to half the number of pages to be displayed on the pages from the first page to Pages to display pages if the current page is greater than half of the number of pages to be displayed is from (the current page-half of the pages to be displayed) displayed to (half of the current page + number of pages to display)--][#macro new_pager url totalpage curpage=1 class= "" showpagenum=5][#local halfpage= ( SHOWPAGENUM/2)? int/][@showFirstPage url=url class=class curpage=1 /][#if (curpage > 1) [@showPrePage url=url class=class curpage=curpage-1 /][/#if][#----Display the middle page start---] [#if ( Showpagenum>=totalpage)] [@showPage start=1 end=totalPage url=url class=class curpage=curpage/][#else] [#if (Halfpage>=curpage)] [@showPage start=1 end=showpagenum url =url class=class curpage=curpage/][#else] [@showPage start= (Curpage-halfpage) end=curpage+ halfpage url=url class=class curpage=curpage/][/#if][/#if][#----Display the middle page end---] [#if (totalpage > curpage) [@showNextPage url=url class=class curpage= (curPage+1) /][/#if] [@showLastPage url=url class=class curpage=totalpage /] Total [${totalpage}] page [/# Macro
This article is from the "Skyarac" blog, make sure to keep this source http://skyarac.blog.51cto.com/5324985/1717927
Freemarker Custom Paging Tool class