首页>代码>ssm(spring+spring mvc+mybatis)高仿小米电子商城项目实例>/gaofang-MilletMall/src/com/shop/common/PageInfo.java
package com.shop.common;
import java.io.Serializable;
public class PageInfo implements Serializable {
private static final long serialVersionUID = 1L;
/** 总记录 */
private int total;
/** 总页数 */
private int totalPage;
/** 数据库中limit的参数,从第几条开始取 */
private int offset;
/** 每页显示的记录数 */
private int limit;
/** 当前页 */
private int current;
/** 排序字段 */
private String sort;
/** ASC,DESC mybatis Order 关键字 */
private String order;
public PageInfo() {
super();
}
public PageInfo(int limit, int current) {
// 计算当前页
if (current < 0) {
this.current = 1;
} else {
// 当前页
this.current = current;
}
// 记录每页显示的记录数
if (limit < 0) {
this.limit = limit;
} else {
this.limit = limit;
}
// 计算开始的记录和结束的记录
this.offset = (this.current - 1) * this.limit;
}
// 构造方法
public PageInfo(int current, int limit, String sort, String order) {
// 计算当前页
if (current < 0) {
this.current = 1;
} else {
// 当前页
this.current = current;
}
// 记录每页显示的记录数
if (limit < 0) {
this.limit = limit;
} else {
this.limit = limit;
}
// 计算开始的记录和结束的记录
this.offset = (this.current - 1) * this.limit;
// 排序字段,正序还是反序
this.sort = sort;
this.order = order;
}
public void count() {
if (limit <= 0) {
this.limit = 1;
}
// 计算总页数
int totalPageTemp = this.total / this.limit;
int plus = (this.total % this.limit) == 0 ? 0 : 1;
totalPageTemp = totalPageTemp + plus;
if (totalPageTemp <= 0) {
totalPageTemp = 1;
}
this.totalPage = totalPageTemp;
}
public void current() {
if (limit <= 0) {
this.limit = 1;
}
// 计算当前页数
this.current = this.offset / this.limit + 1;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
count();
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
current();
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public int getCurrent() {
return current;
}
public void setCurrent(int current) {
this.current = current;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getOrder() {
return order;
}
public void setOrder(String order) {
this.order = order;
}
}
最近下载更多
微信网友_7134912998903808 LV15
2024年9月11日
sweetlove LV20
2024年7月13日
799743530 LV11
2024年7月8日
玖零定制问题修复 LV34
2024年4月4日
微信网友_6699076084797440 LV7
2023年11月2日
gecongkai LV8
2023年6月22日
95959595959 LV13
2023年4月11日
sharkness123 LV8
2023年3月30日
秋枫花落叶 LV2
2022年10月27日
liuxiao2 LV16
2022年10月11日

最近浏览