# 1. 分页

分析 要实现分页要知道数据是在哪里 开始和结束

假设每条显示 10 条数据

# mysql 和 ORACLE 的 SQL 语句不太一样


	msyql 从0开始计数  其中有Limit关键字(Oracle没有)

		select * from student limit  页数*10,10;
	
	Oracle 是从1开始的 
		select * from student where sno>=(n-1)*10+1 and sno<=n*10;(此种写法是有漏洞的,ID值必须是连续的,假如中间有学生退学之类的情况,中间就会出现空位,存在BUG)
		select rownum,t.* from student t where sno<=(n-1)*10+1 and sno>=n*10;这种写法会根绝rownum列进行排序,但是伪列的顺序会被打乱、rownum只能查询小于的数据不能查询大于的数据
		解决方案:分开使用,先只排序,
		a.select s.* from student s order by sno asc ;
		b.select  rownum,t.*from (select s.* from student s order by sno asc) t;
		c.select * from (select  rownum r,t.*from (select s.* from student s order by sno asc) t) where r>= (n-1)*10+1and r<=n*10;//oracle 的分页查询语句

	sql server 的分页查询:
		sql server 2003: top
		select top 页面数 * from student where id not in (
					select top (页面数-1)*页面大小 id from student order by sno sec);

		sql server 2010:
		offset fetch next only 

		select * from student order bu sno 
		offset(页数-1)*页面大小-1 fetch next 页面大小 rows only;

# 分页实现:

封装到一个实体类里面

# 5 个变量(属性)

1. 数据总量
2. 页面大小
3. 总页数
4. 当前页
5. 当前页的对象集合(实体类集合):每页 所显示的所有数据

阅读次数

请我喝[咖啡]~( ̄▽ ̄)~*

Zhouy 支付宝

支付宝

Zhouy 宝贝不是paypal

宝贝不是paypal

Zhouy 微信支付

微信支付