国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
Freemarker分頁(yè) - 石礫 - JavaEye技術(shù)網(wǎng)站

Freemarker分頁(yè)

文章分類(lèi):Java編程

隨筆的一個(gè)記錄。

有兩個(gè)參考類(lèi),

Java代碼
  1. import java.util.List;   
  2.   
  3. /**  
  4.  * 分頁(yè)顯示對(duì)象  
  5.  * @param <T>  
  6.  */  
  7. public class PageView<T> {       
  8.     /** 分頁(yè)數(shù)據(jù) **/  
  9.     private List<T> records;   
  10.     /** 頁(yè)碼開(kāi)始索引和結(jié)束索引 **/  
  11.     private PageIndex pageindex;   
  12.         /** 總頁(yè)數(shù) **/  
  13.     private long totalpage = 1;   
  14.     /** 每頁(yè)顯示記錄數(shù) **/  
  15.        private int maxresult = 12;   
  16.        /** 當(dāng)前頁(yè) **/  
  17.       private int currentpage = 1;   
  18.       /** 總記錄數(shù) **/  
  19.       private long totalrecord;   
  20.       /** 頁(yè)碼數(shù)量 **/  
  21.      private int pagecode = 10;   
  22.   
  23.      /** 要獲取記錄的開(kāi)始索引 **/  
  24.      public int getFirstResult() {   
  25.       
  26.       return (this.currentpage-1) * this.maxresult;   
  27.   
  28.     }   
  29.   
  30.     public int getPagecode() {   
  31.         return pagecode;   
  32.     }   
  33.   
  34.     public void setPagecode(int pagecode) {   
  35.         this.pagecode = pagecode;   
  36.     }   
  37.   
  38.     public PageView(int maxresult, int currentpage) {   
  39.         this.maxresult = maxresult;   
  40.         this.currentpage = currentpage;   
  41.     }   
  42.   
  43.     public void setQueryResult(QueryResult<T> qr){   
  44.              setTotalrecord(qr.getTotal());   
  45.         setRecords(qr.getResultList());   
  46.     }   
  47.   
  48.     public long getTotalrecord() {   
  49.         return totalrecord;   
  50.     }   
  51.   
  52.   
  53.     public void setTotalrecord(long totalrecord) {   
  54.         this.totalrecord = totalrecord;   
  55.         setTotalpage(this.totalrecord % this.maxresult == 0 ? this.totalrecord / this.maxresult : this.totalrecord / this.maxresult + 1);   
  56.     }   
  57.   
  58.     public List<T> getRecords() {   
  59.         return records;   
  60.     }   
  61.   
  62.     public void setRecords(List<T> records) {   
  63.         this.records = records;   
  64.     }   
  65.   
  66.     public PageIndex getPageindex() {   
  67.         return pageindex;   
  68.     }   
  69.   
  70.     public long getTotalpage() {   
  71.                return totalpage;   
  72.     }   
  73.   
  74.     public void setTotalpage(long totalpage) {   
  75.         this.totalpage = totalpage;   
  76.         this.pageindex = PageIndex.getPageIndex(pagecode, currentpage, totalpage);   
  77.     }   
  78.   
  79.   
  80.        
  81.   
  82.   
  83.     /**  
  84.      *  每頁(yè)顯示記錄數(shù)  
  85.      * @return  
  86.      */  
  87.     public int getMaxresult() {   
  88.         return maxresult;   
  89.     }   
  90.   
  91.     public int getCurrentpage() {   
  92.         return currentpage;   
  93.     }   
  94.   
  95.   
  96. }  

 另外一個(gè)

Java代碼
  1. /**  
  2.  * 算出頁(yè)碼的開(kāi)始索引和結(jié)束索引  
  3.  */  
  4.   
  5. public class PageIndex {   
  6.   
  7.     /** 開(kāi)始索引 */  
  8.     private long startindex;   
  9.   
  10.     /** 結(jié)束索引 */  
  11.     private long endindex;   
  12.   
  13.     public PageIndex(long startindex, long endindex) {   
  14.         this.startindex = startindex;   
  15.         this.endindex = endindex;   
  16.     }   
  17.   
  18.     public long getStartindex() {   
  19.         return startindex;   
  20.     }   
  21.   
  22.     public void setStartindex(long startindex) {   
  23.         this.startindex = startindex;   
  24.     }   
  25.   
  26.     public long getEndindex() {   
  27.         return endindex;   
  28.     }   
  29.   
  30.     public void setEndindex(long endindex) {   
  31.         this.endindex = endindex;   
  32.     }       
  33.   
  34.   
  35.     /**  
  36.      * 算出頁(yè)碼的開(kāi)始索引和結(jié)束索引  
  37.      * @param viewpagecount 頁(yè)碼數(shù)量  
  38.      * @param currentPage 當(dāng)前頁(yè)數(shù)  
  39.      * @param totalpage 總頁(yè)數(shù)  
  40.      * @return  
  41.      */  
  42.   
  43.     public static PageIndex getPageIndex(long viewpagecount, int currentPage, long totalpage){   
  44.         long startpage = currentPage - (viewpagecount % 2 == 0 ? viewpagecount / 2 - 1 : viewpagecount / 2);   
  45.         long endpage = currentPage + viewpagecount / 2;   
  46.         if(startpage < 1){   
  47.             startpage = 1;   
  48.             if(totalpage >= viewpagecount) endpage = viewpagecount;   
  49.             else endpage = totalpage;   
  50.         }   
  51.   
  52.   
  53.         if(endpage > totalpage){   
  54.             endpage = totalpage;   
  55.             if((endpage - viewpagecount)> 0) startpage = endpage - viewpagecount + 1;   
  56.             else startpage = 1;   
  57.         }   
  58.   
  59.   
  60.         return new PageIndex(startpage, endpage);           
  61.   
  62.   
  63.     }  

  下面是Freemarker的分頁(yè)宏

Xml代碼
  1. <#-- 總頁(yè)數(shù),當(dāng)前頁(yè) -->  
  2. <#macro pagination pageView>     
  3.     <div class="pages">  
  4.         <label>共${pageView.totalpage}頁(yè),約${pageView.totalrecord}條數(shù)據(jù)</label>  
  5.         <#if pageView.currentpage != 1>  
  6.             <a href="javascript:pageinationView(1)" title="首頁(yè)" class="nav"><span>首頁(yè)</span></a>  
  7.             <a href="javascript:pageinationView(${pageView.currentpage - 1})" title="上一頁(yè)" class="nav"><span>上一頁(yè)</span></a>  
  8.         <#else>  
  9.             <span>首頁(yè)</span>  
  10.             <span>上一頁(yè)</span>  
  11.         </#if>  
  12.            
  13.         <#list pageView.pageindex.startindex..pageView.pageindex.endindex as index>  
  14.             <#if pageView.currentpage == index>  
  15.                 <a href="#" class="current">${index}</a>  
  16.             <#else>  
  17.                 <a href="javascript:pageinationView(${index})" title="第${index}頁(yè)" >${index}</a>     
  18.             </#if>     
  19.         </#list>     
  20.            
  21.         <#if pageView.currentpage != pageView.totalpage>  
  22.             <a href="javascript:pageinationView(${pageView.currentpage + 1})" title="下一頁(yè)" class="nav"><span>下一頁(yè)</span></a>  
  23.             <a href="javascript:pageinationView(${pageView.totalpage})" title="未頁(yè)" class="nav"><span>未頁(yè)</span></a>  
  24.         <#else>  
  25.             <span>下一頁(yè)</span>  
  26.             <span>未頁(yè)</span>  
  27.         </#if>  
  28.     </div>  
  29.     <script type="text/javascript">  
  30.         function pageinationView(pageNum) {   
  31.             document.getElementById("pageNum").value=pageNum;   
  32.             document.getElementById("pageinationForm").submit();   
  33.         }   
  34.     </script>  
  35. </#macro>   
 

頁(yè)面的引用

Html代碼
  1. <!--分頁(yè) -->  
  2.             <form id="pageinationForm" method="post" action="clazz-list">  
  3.                 <input type="hidden" id="pageNum" name="pageNum" value="${pageNum}" />  
  4.             </form>  
  5.             <#import "*/main/main-page.ftl" as pager>  
  6.             <@pager.pagination pageViewpageView=pageView/>  
  7.            <!-- 分頁(yè) -->  

 現(xiàn)在應(yīng)該出來(lái)了基本的分頁(yè)。等后續(xù)的工作完成再記錄!

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
jsp標(biāo)簽分頁(yè)
s2sh 底層封裝(增,刪,改,查,分頁(yè))
刪除最后一頁(yè)的最后一條數(shù)據(jù),沒(méi)回到前一頁(yè)
Bootstrap之翻頁(yè)
最好的PHP分頁(yè)類(lèi)
SSH分頁(yè)技術(shù)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服