最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java(基于Struts2) 分頁實(shí)現(xiàn)代碼

 更新時(shí)間:2013年10月02日 16:25:33   作者:  
這篇文章介紹了Java(基于Struts2) 分頁實(shí)現(xiàn)代碼,有需要的朋友可以參考一下

分頁實(shí)現(xiàn)的基本過程是這樣的:

1. 設(shè)置自己的分頁器的基本參數(shù)(可以從配置文件中讀?。?/P>

  ■每頁顯示的記錄條數(shù)

  ■每次最多顯示多少頁

2. 編寫設(shè)置分頁器其他參數(shù)的函數(shù)

    主要參數(shù)有以下幾個(gè):

    總記錄條數(shù)

    總頁數(shù)

    當(dāng)前頁號:現(xiàn)在顯示的頁數(shù)

    每頁顯示的記錄條數(shù)

    當(dāng)前頁開始行(第一行是0行)

    第一頁頁號

    最后頁頁號

    下一頁頁號

    上一頁頁號

    畫面上顯示的起始頁號

    畫面上顯示的結(jié)束頁號

    參數(shù)基本實(shí)現(xiàn)原理:設(shè)置以上各個(gè)參數(shù),實(shí)際上只需要三個(gè)參數(shù)就可以對所有的其他變量進(jìn)行設(shè)置,即總記錄條數(shù),每頁顯示記錄數(shù),每次最多顯示多少頁。

    分頁器的代碼實(shí)現(xiàn)如下(省略get,set函數(shù)):

    Page.java

復(fù)制代碼 代碼如下:

{
        this.onePageSize = Integer.valueOf(PageResource.get(PageResource.ONE_PAGE_SIZE));
        this.displayPageCount = Integer.valueOf(PageResource.get(PageResource.DISPLAY_PAGE_COUNT)) - 1;
    }

    /** 頁號式導(dǎo)航, 最多顯示頁號數(shù)量為displayPageCount+1 */
    private int displayPageCount;

    /** 每頁顯示的記錄條數(shù) */
    private int onePageSize;

    /** 總記錄條數(shù) */
    private int totalRecord;

    /** 總頁數(shù) */
    private int totalPage;

    /** 當(dāng)前頁號 */
    private int currentPageNum = 1;

    /** 當(dāng)前頁開始行(第一行是0行) */
    private int currentStartRow;

    /** 第一頁頁號 */
    private int firstPageNum = 1;

    /** 最后頁頁號 */
    private int lastPageNum;

    /** 下一頁頁號 */
    private int nextPageNum;

    /** 上一頁頁號 */
    private int prevPageNum;

    /** 頁號式導(dǎo)航 起始頁號 */
    private int startPageNum;

    /** 頁號式導(dǎo)航 結(jié)束頁號 */
    private int endPageNum;

    /**
     *
     * @param onePageSize
     * @param currentPageNum
     * @param totalRecord
     */
    public Page(int totalRecord) {
        this.totalRecord = totalRecord;
        this.setPageInfo();
    }

    public Page() {
    }

    public void setPageInfo() {
        this.totalPage = (totalRecord + onePageSize - 1) / onePageSize;
        this.currentPageNum = Math.max(1, Math.min(currentPageNum, totalPage));

        this.lastPageNum = this.totalPage;
        this.nextPageNum = Math.min(this.totalPage, this.currentPageNum + 1);
        this.prevPageNum = Math.max(1, this.currentPageNum - 1);

        // 分頁控制信息
        this.currentStartRow = (this.currentPageNum - 1) * onePageSize;

        startPageNum = Math.max(this.currentPageNum - displayPageCount / 2,
                firstPageNum);
        endPageNum = Math.min(startPageNum + displayPageCount, lastPageNum);
        if (endPageNum - startPageNum < displayPageCount) {
            startPageNum = Math.max(endPageNum - displayPageCount, 1);
        }
    }


3. 編寫前端代碼(以Struts2為例)

當(dāng)在前臺點(diǎn)擊各個(gè)跳轉(zhuǎn)頁面的鏈接時(shí),只需要將要跳轉(zhuǎn)到的頁號和總頁數(shù)傳給后臺,后臺會重新更新分頁器,進(jìn)而實(shí)現(xiàn)頁碼的跳轉(zhuǎn)。

復(fù)制代碼 代碼如下:

<div>
            <div>
                總頁數(shù):
                <s:property value="#request.p.totalPage" />
                總記錄數(shù):
                <s:property value="#request.p.totalRecord" />
            </div>
            <s:url id="firstURL" action="PageAction!toPage">
                <s:param name="p.currentPageNum">
                    <s:property value="#request.p.firstPageNum" />
                </s:param>
                <s:param name="p.totalRecord">
                    <s:property value="#request.p.totalRecord" />
                </s:param>
            </s:url>
            <s:a href="%{firstURL}">首頁</s:a>

            <s:url id="prev" action="PageAction!toPage">
                <s:param name="p.currentPageNum">
                    <s:property value="#request.p.prevPageNum" />
                </s:param>
                <s:param name="p.totalRecord">
                    <s:property value="#request.p.totalRecord" />
                </s:param>
            </s:url>
            <s:a href="%{prev}">上一頁</s:a>

            <s:bean name="org.apache.struts2.util.Counter" id="counter">
                <s:param name="first" value="p.startPageNum" />
                <s:param name="last" value="p.endPageNum" />
                <s:iterator var="pageNum">
                    <s:if test="p.currentPageNum==#pageNum">
                        <s:property />
                    </s:if>
                    <s:else>
                        <s:url id="page" action="PageAction!toPage">
                            <s:param name="p.currentPageNum">
                                <s:property value="#pageNum" />
                            </s:param>
                            <s:param name="p.totalRecord">
                                <s:property value="#request.p.totalRecord" />
                            </s:param>
                        </s:url>
                        <s:a href="%{page}"><s:property /></s:a>
                    </s:else>
                </s:iterator>
            </s:bean>

            <s:url id="next" action="PageAction!toPage">
                <s:param name="p.currentPageNum">
                    <s:property value="#request.p.nextPageNum" />
                </s:param>
                <s:param name="p.totalRecord">
                    <s:property value="#request.p.totalRecord" />
                </s:param>
            </s:url>
            <s:a href="%{next}">下一頁</s:a>

         <s:url id="lastURL" action="PageAction!toPage">
                <s:param name="p.currentPageNum">
                    <s:property value="#request.p.lastPageNum" />
                </s:param>
                <s:param name="p.totalRecord">
                    <s:property value="#request.p.totalRecord" />
                </s:param>
            </s:url>
         <s:a href="%{lastURL}">尾頁</s:a>
        </div>

相關(guān)文章

最新評論

广河县| 丰顺县| 鄂托克旗| 昌吉市| 铜鼓县| 唐海县| 重庆市| 汶川县| 盐城市| 茌平县| 正安县| 鹤庆县| 平泉县| 满洲里市| 南乐县| 翁源县| 项城市| 安多县| 中江县| 三穗县| 长垣县| 龙南县| 阳曲县| 唐海县| 瑞丽市| 龙陵县| 巴青县| 宁津县| 阳曲县| 措美县| 黄平县| 福鼎市| 久治县| 平舆县| 前郭尔| 耒阳市| 友谊县| 康马县| 巴林右旗| 清涧县| 五台县|