package com.siku.base.action;
import java.util.ArrayList;
import java.util.Collection;
import com.opensymphony.xwork2.ActionSupport;
/**
* 是Action类的基类,供分页使用
*/
public abstract class BaseAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private final static int PAGE_SIZE = 10;
private int totalRows; // 总行数
private int pageSize = PAGE_SIZE; // 每页显示的行数
private int currentPage; // 当前页号
private int totalPages; // 总页数
private boolean hasNext; // 是否有下一页
private boolean hasPrevious; // 是否有上一页
private Collection<Integer> indexList; // 页码集合
/**
* 这里最好用一个引用参数化
*/
public Collection<Integer> getIndexList() {
ArrayList<Integer> result = new ArrayList<Integer>();
for (int i = 1; i <= getTotalPages(); i++) {
result.add(new Integer(i));
}
indexList = result;
return indexList;
}
public void setIndexList(Collection<Integer> indexList) {
this.indexList = indexList;
}
public boolean isHasNext() {
return hasNext;
}
public void setHasNext(boolean hasNext) {
this.hasNext = hasNext;
}
public boolean isHasPrevious() {
return hasPrevious;
}
public void setHasPrevious(boolean hasPrevious) {
this.hasPrevious = hasPrevious;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
/*
* public void previous() { //上一页 if (currentPage == 1) { return; }
* currentPage--; }
*
* public void next() { //下一页 if (currentPage < totalPages) { currentPage++;
* } }
*/
public void first() { // 首页
currentPage = 1;// 当前页号
}
public void last() { // 尾页
currentPage = totalPages;// 当前页号=总页数
}
/**
* 分页算法从什么位置开始讀取
*
* @return
*/
public int getStartRow() {
if (getCurrentPage() == 1)
return 0;
else
return (getCurrentPage() - 1) * pageSize;
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
/**
* 分页列表函数
*
* @param hsql
* @return
* @throws Exception
*/
public Collection<?> pageList(Object obj) throws Exception {
try {
// totalRows = this.userInfoService.getCountSize(obj); // 总行数
totalPages = (totalRows + pageSize - 1) / pageSize; // 总页数
this.setIndexList(getIndexList()); // 生成页码集合1,2,3,4..
if (currentPage == 0 || currentPage < 1) {
first();
}
if (currentPage > totalPages) {
last();
}
if (currentPage >= 1 && currentPage < totalPages) {
hasNext = true;
}
if (currentPage > 1 && currentPage <= totalPages) {
hasPrevious = true;
}
return null;
// return userInfoService.findWithPageList(obj, getStartRow(),
// PAGE_SIZE);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
Spring集成JMS
3星 · 超过75%的资源 需积分: 9 133 浏览量
2010-02-10
12:10:38
上传
评论 1
收藏 24KB RAR 举报
feitianmao1122
- 粉丝: 1
- 资源: 2
最新资源
- libjpeg 编译所需的 Win32.mak vs编译libjpeg
- 自动驾驶-状态估计和定位-粒子滤波实现和源码.pdf
- 数据可视化-智慧物流服务中心大屏页面.zip
- yolov5,SSD 可能使用到的一些代码
- bbbbbbbbbbbbbbbbbb
- 安卓逆向学习笔记之Frida Stalker 还原OLLVM AES.docx
- 安卓逆向学习笔记之unicorn来trace还原OLLVM Base64.docx
- 基于jquery的自定义表格组件实现
- Nessus最新20240426离线安装插件all-2.0.tar.gz
- 最新版本私钥助记词碰撞器大富豪使用python进行制作通过接口的方式进行验证支持多币种多链多网络一分钟万次验证高出货率
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈