JavaWeb 分页

三个条件

1.总共多少条记录
2.每页多少条
3.请求第几页

SQL
oracle:

select * from (select c.*,rownum r from category c) where r>=11 and r<=15

分页信息封装一个类PageInfo

package com.page;

public class PageInfo {

    // 1,总记录条数
    // 2,一页显示多少条
    // 3,请求页码
    private int totalPageCount;//总页数

    private int currentPageCount = 5;
    private int requestPage = 1;
    // begin =(requestPage-1)*currentPageCount+1;
    // end =requestPage*currentPageCount;
    private int begin;
    private int end;

    private int totalRecordCount;//总记录条数

    private int previousPage;//上一页

    private int nextPage;//下一页



    public int getTotalRecordCount() {
        return totalRecordCount;
    }

    public void setTotalRecordCount(int totalRecordCount) {
        this.totalRecordCount = totalRecordCount;
    }

    public int getPreviousPage() {
        return previousPage=requestPage>1?(requestPage-1):1;
    }


    public int getNextPage() {
        int total = getTotalPageCount();
        return nextPage=requestPage<total?(requestPage+1):total;
    }


    public PageInfo(int requestPage) {
        this.requestPage = requestPage;
        this.begin = (requestPage - 1) * this.currentPageCount + 1;
        this.end = requestPage * this.currentPageCount;
    }

    public int getTotalPageCount() {

        int totalRecord=getTotalRecordCount();
        int count=getCurrentPageCount();
        int total=totalRecord>count?(totalRecord/count)+1:1;
        return total;
    }

    public int getCurrentPageCount() {
        return currentPageCount;
    }

    public void setCurrentPageCount(int currentPageCount) {
        this.currentPageCount = currentPageCount;
    }

    public int getRequestPage() {
        return requestPage;
    }

    public void setRequestPage(int requestPage) {
        this.requestPage = requestPage;
    }

    public int getBegin() {
        return begin;
    }

    public void setBegin(int begin) {
        this.begin = begin;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }


}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值