SQL-借助伪列实现分页查询

//SQL测试数据自我复制
//将查询结果插入表无需写values();

insert into news(nid,ntid,ntitle,nauthor,ncreatedate,npicpath,nmodifydate,nsummary,ncontent) 
select nid_seq.nextval,ntid,ntitle,nauthor,ncreatedate,npicpath,nmodifydate,nsummary,ncontent from news;
commit;

//子查询把全部内容和伪列rownum(as rn)全部查询,再从子查询中通过rn进行数字分页

select * from (select rownum as rn,nid,ntid,ntitle,nauthor,ncreatedate,npicpath,nmodifydate,nsummary,ncontent from news);

//构建一个Pagenation分页工具类,在Biz层和Dao层之间通过它实现分页

package com.sm.util;

import java.util.List;

public class Pagenation<T> {
	private int pageNo;
	private int pageSize = 10;
	private int totalRows;
	private int totalPages;
	private int prePage;
	private int nextPage;
	private List<T> items;

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public List<T> getItems() {
		return items;
	}

	public void setItems(List<T> items) {
		this.items = items;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getTotalPages() {
		if(totalRows%pageSize==0){
			totalPages=totalRows/pageSize;
		}else{
			totalPages=totalRows/pageSize+1;
		}
		return totalPages;
	}

	/*public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}*/

	public int getPrePage() {
		return prePage;
	}

	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值