<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 241,  comments - 116,  trackbacks - 0
    分頁處理、儲存工具類。
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;

    /**
     * 儲存分頁處理工具類 在調(diào)用此類的方法之前需設(shè)置總頁數(shù)(即得先從數(shù)據(jù)庫查詢到相應(yīng)數(shù)據(jù)的數(shù)據(jù)量)
     *
     * @author ahomeeye
     * @version 1.0
     */
    public class Pagination implements Serializable {

        private static final long serialVersionUID = 1L;
        public final static String FIRST_ACTION = "First"; // 執(zhí)行跳到第一頁操作
        public final static String NEXT_ACTION = "Next"; // 執(zhí)行跳到下一頁操作韓國女裝
        public final static String PREVIO_ACTION = "Prev"; // 執(zhí)行跳到上一頁操作
        public final static String LAST_ACTION = "Last"; // 執(zhí)行跳到最一頁操作
        public final static String CURRENT_TAG = "currentPage"; // 當(dāng)前頁數(shù)
        public final static String PAGINATION_ACTION_TAG = "paginationAction"; // 緩存操作
        public final static String GOTO_PAGE_ACTION = "gotoPage"; // 執(zhí)行跳到指定的某一頁操作
        public final static String PAGES_GOTO = "pageSelect"; // 執(zhí)行g(shù)oto操作時,用戶所指定的頁數(shù)
        http://hanguonvzhuang.blogcn.com/articles/2011/09/page/2
        private int start; // start表示當(dāng)前頁開始的記錄數(shù),start=每頁行數(shù)*(當(dāng)前頁數(shù)-1)
        private int end; // 當(dāng)前頁結(jié)束的記錄行數(shù)
        private int totalCount; // 總行數(shù)
        private int rowsPerPage = 15; // 每頁行數(shù),默認(rèn)15
        private int currentPage; // 當(dāng)前頁數(shù)
        private int pageListSize = 9;// 頁碼列表大小,默認(rèn)9
        private List<Integer> pageNumList = new ArrayList<Integer>();

        public Pagination() {
            start = 0;
            end = 0;
            currentPage = 1;
            this.totalCount = 0;
        }

        public Pagination(int totalCount) {
            start = 0;
            end = 0;
            currentPage = 1;
            this.totalCount = totalCount;
        }

        public Pagination(int totalCount, int numPerPage) {
            start = 0;
            end = 0;
            this.totalCount = totalCount;
            currentPage = 1;
            if (numPerPage > 0) {
                rowsPerPage = numPerPage;
            }
        }

        /**
         * 執(zhí)行翻頁動作
         *
         * @param currentPage
         *            要翻到的目標(biāo)頁碼
         * @return 返回翻頁對象
         */
        public Pagination doPagination(int currentPage) {
            gotoPage(currentPage);
            return this;
        }

        // 設(shè)置起始數(shù)
        public int getStart() {
            start = rowsPerPage * (currentPage - 1);
            return start;
        }

        // 得到起始數(shù)
        public void setStart(int start) {
            if (start < 0) {
                this.start = 0;
            } else if (start >= this.totalCount) {
                this.start = this.totalCount - 1;
            } else {
                this.start = start;
            }
        }

        // 設(shè)置當(dāng)前頁的最后一行的在總記錄中的順序(從0開始)
        public void setEnd(int end) {
            this.end = end;
        }

        // 得到當(dāng)前頁的最后一行的在總記錄中的順序(從0開始)
        public int getEnd() {
            if (rowsPerPage * currentPage > this.totalCount) {
                end = this.totalCount - 1;
            } else {
                end = rowsPerPage * currentPage - 1;
            }
            return end;
        }

        // 以下4個方法供控制器(struts)調(diào)用

        // 判斷能否到第一頁;只要能到上一頁,肯定就有第一頁
        public boolean firstEnable() {
            return previousEnable();
        }

        // 判斷能否到上一頁
        public boolean previousEnable() {
            return currentPage > 1;// 只要不是第一頁,就能到上一頁
        }

        // 判斷能否到下一頁
        public boolean nextEnable() {
            return currentPage * rowsPerPage < this.totalCount;
        }

        // 判斷能否到最后一頁;只要有下一頁,就肯定有最后一頁.
        public boolean lastEnable() {
            return nextEnable();
        }

        // 跳到第一頁
        public void firstPage() {
            currentPage = 1;
        }

        // 跳到上一頁
        public void previousPage(int cPage) {
            currentPage = (cPage - 1) > 0 ? (cPage - 1) : 1;
        }

        // 跳到下一頁
        public void nextPage(int cPage) {
            currentPage = cPage + 1;
            if (currentPage * rowsPerPage > this.totalCount) {
                lastPage();
            }
        }

        // 跳到最后一頁
        public void lastPage() {
            if (this.totalCount % rowsPerPage == 0) {
                currentPage = this.totalCount / rowsPerPage;
            } else {
                currentPage = this.totalCount / rowsPerPage + 1;
            }
        }

        // 跳到指定的某一頁
        public void gotoPage(int pageNumber) {
            if (pageNumber <= 1) {
                currentPage = 1;
            } else if (getTotalCount() < this.getRowsPerPage()) {
                currentPage = 1;
            } else if (pageNumber * rowsPerPage >= this.totalCount) {
                lastPage();
            } else {
                currentPage = pageNumber;
            }
        }

        // 設(shè)置總行數(shù)
        public void setTotalCount(int totalCount) {
            this.totalCount = totalCount;
        }

        // 得到總行數(shù)
        public int getTotalCount() {
            return totalCount;
        }

        // 設(shè)置每頁行數(shù)
        public void setRowsPerPage(int rowsPerPage) {
            this.rowsPerPage = rowsPerPage;
        }

        // 得到每頁行數(shù)
        public int getRowsPerPage() {
            return rowsPerPage;
        }

        // 得到總頁數(shù)
        public int getPages() {
            if (this.totalCount % rowsPerPage == 0)
                return this.totalCount / rowsPerPage;
            else
                return this.totalCount / rowsPerPage + 1;
        }

        // 得到當(dāng)前頁數(shù)
        public int getCurrentPage() {
            return currentPage;
        }

        // 設(shè)置當(dāng)前頁數(shù)
        public void setCurrentPage(int currentPage) {
            this.currentPage = currentPage;
        }

        public int getPageListSize() {
            return pageListSize;
        }

        // 設(shè)置頁碼列表大小
        public void setPageListSize(int pageListSize) {
            this.pageListSize = pageListSize;
        }

        // 得到頁面列表
        public List<Integer> getPageNumList() {
            this.pageNumList.removeAll(this.pageNumList);// 設(shè)置之前先清空
            int totalPage = getPages();
            if (totalPage > this.pageListSize) {
                int halfSize = this.pageListSize / 2;
                int first = 1;
                int end = 1;
                if (this.currentPage - halfSize < 1) { // 當(dāng)前頁靠近最小數(shù)1
                    first = 1;
                    end = this.pageListSize;
                } else if (totalPage - this.currentPage < halfSize) { // 當(dāng)前頁靠近最大數(shù)
                    first = totalPage - this.pageListSize + 1;
                    end = totalPage;
                } else {
                    first = this.currentPage - halfSize;
                    end = this.currentPage + halfSize;
                }
                for (int i = first; i <= end; i++) {
                    this.pageNumList.add(i);
                }
            } else {
                for (int i = 0; i < totalPage; i++) {
                    this.pageNumList.add(i + 1);
                }
            }

            return pageNumList;
        }
    }
    posted on 2011-09-19 11:21 墻頭草 閱讀(3466) 評論(1)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    人人游戲網(wǎng) 軟件開發(fā)網(wǎng) 貨運專家
    主站蜘蛛池模板: 亚洲国产精品无码久久九九大片 | 在线观看亚洲AV日韩A∨| 女人隐私秘视频黄www免费| 久久亚洲成a人片| 国产亚洲男人的天堂在线观看 | 中美日韩在线网免费毛片视频| 精品国产免费一区二区| 亚洲丰满熟女一区二区哦| 免费无码黄网站在线观看| 亚洲AV日韩AV一区二区三曲| 国产成人免费全部网站| 色www免费视频| 久久久久亚洲?V成人无码| 两个人看的www高清免费观看| 亚洲精品午夜无码电影网| 永久免费av无码入口国语片| 久久精品亚洲综合| 巨波霸乳在线永久免费视频| 国产成人精品日本亚洲专一区| 岛国片在线免费观看| 色欲aⅴ亚洲情无码AV| JLZZJLZZ亚洲乱熟无码| 国产午夜不卡AV免费| 亚洲男女一区二区三区| 毛片免费视频观看| 特黄aa级毛片免费视频播放| 国产亚洲精品一品区99热| 免费国产成人高清在线观看网站| 亚洲欧美日韩综合俺去了| 亚洲欧洲久久久精品| 无码日韩精品一区二区免费暖暖 | 亚洲熟女乱综合一区二区| 免费无码av片在线观看| 亚洲国产夜色在线观看| 国产免费人成在线视频| 五月婷婷综合免费| 免费观看又污又黄在线观看| 国产成人青青热久免费精品| a级成人毛片免费视频高清| 国产在线观看免费av站| 亚洲精品欧洲精品|