求一份JavaBean中实现MySql分页的代码,可以传递参数的,方便调用,不要写在JSP页面里面的
1个回答
展开全部
mysql有limit好像比较给力,分页也不是很难。
public class PageInfo implements Serializable {
private static final long serialVersionUID = 1365747893051987016L;
private int pageSize = 10; // 每页显示10行,可自行调节
private int recordCount; // 总行数
private int pageCount; // 总页数
private int pageId; // 当前页
private int startIndex; // 当前页的开始行数
private int endIndex; // 当前页的结束行数
private List items;//当前页数据
public PageInfo() {
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getRecordCount() {
return recordCount;
}
public void setRecordCount(int recordCount) {
this.recordCount = recordCount;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageId() {
return pageId;
}
public void setPageId(int pageId) {
this.pageId = pageId;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public int getEndIndex() {
return endIndex;
}
public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}
public List getItems() {
return items;
}
public void setItems(List items) {
this.items = items;
}
}
翻页直接对pageId(当前页)进行加减就可以了,有当前页开始行数,你直接
limit(startIndex-1)*pageSize,pageSize)就可以了
public class PageInfo implements Serializable {
private static final long serialVersionUID = 1365747893051987016L;
private int pageSize = 10; // 每页显示10行,可自行调节
private int recordCount; // 总行数
private int pageCount; // 总页数
private int pageId; // 当前页
private int startIndex; // 当前页的开始行数
private int endIndex; // 当前页的结束行数
private List items;//当前页数据
public PageInfo() {
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getRecordCount() {
return recordCount;
}
public void setRecordCount(int recordCount) {
this.recordCount = recordCount;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageId() {
return pageId;
}
public void setPageId(int pageId) {
this.pageId = pageId;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public int getEndIndex() {
return endIndex;
}
public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}
public List getItems() {
return items;
}
public void setItems(List items) {
this.items = items;
}
}
翻页直接对pageId(当前页)进行加减就可以了,有当前页开始行数,你直接
limit(startIndex-1)*pageSize,pageSize)就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询