Day0831(下午)Oracle数据库分页效果在jsp页面中的显示

笔记:

--mysql: limit
--oracle:rownum伪列
--伪列:在表结构中不存在的列
--rowid伪列:用于唯一标识一行记录
--rownum伪列:行号

select * from emp;--看不到行号

select e.*,rownum from emp e;--正确的

--rownum:行号是从1开始的,也就是有了1才会有2

--分页
--每页显示2条,显示第2页的数据
--pageIndex:第几页(当前页码)
--pageSize:每页显示的记录数
--startRow:(pageIndex-1)*pageSize==>(2-1)2==>2
--endRow:pageIndex*pageSize==>2*2=4
--select * from emp where rownum>startRow and rownum<=endRow
/*
select * from(
select e.*,rownum from emp e where rownum<=endRow
)tmp
where tmp.rownum>startRow
*/
select e.*,rownum from emp e;
select * from (
   select e.*,rownum rn from emp e where rownum<=4
) tmp
where tmp.rn>2;

public class PageBean<T>{
    private int pageIndex;//当前页码
    private int pageSize;//每页显示的记录数
    private int pageCount;//总页码
    private int totalCount;//总记录数
    private List<T> list;//当前分页查询的数据
    public Integer getPageIndex(){
        return pageIndex;
    }    
    public void setPageIndex(Integer pageIndex){
        if(pageIndex>0){
            this.pageIndex = pageIndex;
        }else{
            this.pageIndex = 1 ;
        }
    }
    public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
		setPageCount();
	}
	public Integer getPageCount() {
		return pageCount;
	}
    public void setPageCount(){
        //pageSize不能等于0
        this.pageCount = this.totalCount%thisSize==0?
        this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;
    }
    public Integer getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
		setPageCount();
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
}

猜你喜欢

转载自blog.csdn.net/sinat_41897556/article/details/82286600