org.springside.modules.orm中的page类自我解读
2024-10-19 12:48:02
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.StringUtils; public class Page<T> { /*静态变量,用于设置结果是按照正序排列还是反序排列*/
public static final String ASC = "asc";
public static final String DESC = "desc"; /*当前页码*/
protected int pageNo = 1;
/*页面容量*/
protected int pageSize = 1;
/*orderBy表示通过那个进行排序,比如说:id*/
protected String orderBy = null;
/*order是设置以哪种方式进行排序:可以使ASC也可以是DESC*/
protected String order = null;
/*只是是否自动计算*/
protected boolean autoCount = true; /*以下2个参数常作为 分页所需的"返回结果"! */
//result表示当页面存在的实体类集合。
protected List<T> result = Collections.emptyList();
//totalCount表示当前页面总条数。
protected long totalCount = -1L; public Page() {
} public Page(int pageSize) {
this.setPageSize(pageSize);
} public Page(int pageSize, boolean autoCount) {
this.setPageSize(pageSize);
this.setAutoCount(autoCount);
} public int getPageNo() {
return this.pageNo;
} public void setPageNo(int pageNo) {
this.pageNo = pageNo;
if(pageNo < 1) {
this.pageNo = 1;
} } public int getPageSize() {
return this.pageSize;
} public void setPageSize(int pageSize) {
this.pageSize = pageSize;
if(pageSize < 0) {
this.pageSize = 1;
} } /**
* 获得当前页面第一条数据的排列
* @return
*/
public int getFirst() {
return (this.pageNo - 1) * this.pageSize + 1;
} public String getOrderBy() {
return this.orderBy;
} public void setOrderBy(String orderBy) {
this.orderBy = orderBy;
} public boolean isOrderBySetted() {
return StringUtils.isNotBlank(this.orderBy) && StringUtils.isNotBlank(this.order);
} public String getOrder() {
return this.order;
} public void setOrder(String order) {
String[] orders = StringUtils.split(StringUtils.lowerCase(order), ',');
String[] var6 = orders;
int var5 = orders.length; for(int var4 = 0; var4 < var5; ++var4) {
String orderStr = var6[var4];
if(!StringUtils.equals("desc", orderStr) && !StringUtils.equals("asc", orderStr)) {
throw new IllegalArgumentException("排序方向" + orderStr + "不是合法值");
}
} this.order = StringUtils.lowerCase(order);
} public boolean isAutoCount() {
return this.autoCount;
} public void setAutoCount(boolean autoCount) {
this.autoCount = autoCount;
} public List<T> getResult() {
return this.result;
} public void setResult(List<T> result) {
this.result = result;
} public long getTotalCount() {
return this.totalCount;
} public void setTotalCount(long totalCount) {
this.totalCount = totalCount;
} /**
* 获取一共有多少页(设置的是总条数)
* @return
*/
public long getTotalPages() {
if(this.totalCount < 0L) {
return -1L;
} else {
long count = this.totalCount / (long)this.pageSize;
if(this.totalCount % (long)this.pageSize > 0L) {
++count;
} return count;
}
} /**
* 是否还有下一页
* @return
*/
public boolean isHasNext() {
return (long)(this.pageNo + 1) <= this.getTotalPages();
} /**
* 得到下一页的页码
* @return
*/
public int getNextPage() {
return this.isHasNext()?this.pageNo + 1:this.pageNo;
} /**
* 是否有上一页
* @return
*/
public boolean isHasPre() {
return this.pageNo - 1 >= 1;
} /**
* 得到上一页页码
* @return
*/
public int getPrePage() {
return this.isHasPre()?this.pageNo - 1:this.pageNo;
}
}
对于上述代码需要有几点强调的:
1.Page类本质来讲仅仅是一个辅助类,其中包含的是一些争对分页的辅助数据,具体怎么用,还是需要自己进行处理的。
2.XXX随时补充。。。
最新文章
- IOS开发基础知识--碎片34
- 数据挖掘算法(一)C4.5
- mybatis单个插入和批量插入的简单比较
- String的hashCode原理
- 第四节:教你如何快速让浏览器兼容ES6特性
- hdu4734(数位dp)
- CopyOnWriteArrayList源代码阅读器
- 团队作业4---第一次项目冲刺(ALpha)版本 第七天
- soj4538: ShouHuXueJie Problem DFS
- 20165223《网络对抗技术》Exp3 免杀原理与实践
- 2013年省赛I题 Thrall’s Dream
- 用beam实现连接kafka和elasticSearch示例 在flink平台运行
- Linux超级守护进程&mdash;&mdash;xinetd
- jQuery-3.事件篇---键盘事件
- [Codeforces896C] Willem, Chtholly and Seniorious (ODT-珂朵莉树)
- select * 和select 所有字段的区别
- iOS开发-- 一个苹果证书如何多次使用
- python爬虫之登录
- ApiPost接口调试工具模拟Post上传文件(中文版Postman)
- uoj#228. 基础数据结构练习题(线段树区间开方)
热门文章
- pulseaudio的交叉编译
- Mycat 依赖包解读
- List<;string[]>; 如何去重
- UVALive 2678 大于s的最短子序列和
- iOS高德地图自定义annotation添加不同图片
- Jquery的parent和parents(找到某一特定的祖先元素)
- HDU4325--Flowers--树状数组,离散化
- Node.js学习 - Global Object
- IP地址、子网掩码详解
- System.Text.RegularExpressions.Regex