您的位置:首页 > 数据库

分页查询SQL&&Page对象

2017-05-03 23:33 330 查看
Mysql 分页查询: select * from 表明 where 1=1 limit 0,10

limit 0,10

0 代表数据库里 记录 起始行的下标 =(当前页页码-1)*每页显示的数据量

10代表每页 多少条

SQL Server 语法 :select top 3 * from NEWS where ID not in

(select top 0 ID from NEWS)

内层 select top 0 ID from NEWS 0 代表数据库里 记录 起始行的下标 =(当前页页码-1)*每页显示的数据量

外层 select top 3 代表每次 返回多少条

//page 类用来做分页
public class Page {
//current page 当前页码
private int currPage;
//pagesize 每页数量
private int pageSize;
//total count 总条数
private int totalCount;
//totalpage 总页数
private int totalPageCount;
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
//设置记录总条数时,顺便计算一下总页数
this.totalCount = totalCount;
if(totalCount%pageSize==0){
this.totalPageCount = totalCount/pageSize;
}else{
this.totalPageCount = totalCount/pageSize+1;
}

}
public int getTotalPageCount() {
return totalPageCount;
}

public Page(int currPage, int pageSize, int totalCount, int totalPageCount) {
super();
this.currPage = currPage;
this.pageSize = pageSize;
this.totalCount = totalCount;
this.totalPageCount = totalPageCount;
}
public Page() {
super();
// TODO Auto-generated constructor stub
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  分页 mysql 数据库