Page分页
来源:互联网 发布:知乎暨南大学临床医学 编辑:程序博客网 时间:2024/05/18 20:51
Page.java:
package com.qddx.wmal.dao.impl;
public class Page {
private int everyPage; // 每页显示数量
private int totalCount; // 总记录数
private int totalPage; // 总页数
private int currentPage; // 当前页码
private int beginIndex; // 起始点
private boolean hasPrePage; // 是否有上一页
private boolean hasNextPage; // 是否有下一页
public Page(int everyPage, int totalCount, int totalPage, int currentPage,
int beginIndex, boolean hasPrePage, boolean hasNextPage) {
super();
this.everyPage = everyPage;
this.totalCount = totalCount;
this.totalPage = totalPage;
this.currentPage = currentPage;
this.beginIndex = beginIndex;
this.hasPrePage = hasPrePage;
this.hasNextPage = hasNextPage;
}
public Page() {
}
public int getEveryPage() {
return everyPage;
}
public void setEveryPage(int everyPage) {
this.everyPage = everyPage;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getBeginIndex() {
return beginIndex;
}
public void setBeginIndex(int beginIndex) {
this.beginIndex = beginIndex;
}
public boolean isHasPrePage() {
return hasPrePage;
}
public void setHasPrePage(boolean hasPrePage) {
this.hasPrePage = hasPrePage;
}
public boolean isHasNextPage() {
return hasNextPage;
}
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}
}
PageUtil.java
package com.qddx.wmal.dao.impl;
public class PageUtil {
public static Page createPage(int everyPage, int totalCount, int currentPage) {
//每页记录数
everyPage = getEveryPage(everyPage);
//当前页
currentPage = getCurrentPage(currentPage);
//总页数
int totalPage = getTotalPage(everyPage, totalCount);
//起始点
int beginIndex = getBeginIndex(everyPage, currentPage);
//是否有上一页
boolean hasPrePage = getHasPrePage(currentPage);
//是否有下一页
boolean hasNextPage = getHasNextPage(totalPage, currentPage);
return new Page(everyPage, totalCount, totalPage, currentPage,
beginIndex, hasPrePage, hasNextPage);
}
//得到当前页记录数
public static int getEveryPage(int everyPage){
return everyPage;
}
//得到当前页码
public static int getCurrentPage(int currentPage){
return currentPage == 0 ? 1 : currentPage;
}
//得到总页数
public static int getTotalPage(int everyPage, int totalCount){
int totalPage = 0;
if(totalCount % everyPage == 0){
totalPage = totalCount/everyPage;
}else{
totalPage = totalCount/everyPage + 1;
}
return totalPage;
}
//得到每页起始点
public static int getBeginIndex(int everyPage, int currentPage){
return (currentPage - 1) * everyPage;
}
//是否上一页
public static boolean getHasPrePage(int currentPage){
return currentPage == 1 ? false : true;
}
//是否有下一页
public static boolean getHasNextPage(int totalPage, int currentPage){
return totalPage == currentPage || totalPage == 0 ? false : true;
}
}
Action.java
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getCurrentPage() {
return currentPage;
}
public String showCartes() throws Exception{
List<Carte> cartes = carteHibernate.findByRes((Res) session.get("res"));
Page page = PageUtil.createPage(everyPage, cartes.size(), currentPage);
int endIndex = page.getBeginIndex() + page.getEveryPage();
if(endIndex > page.getTotalCount()){
endIndex = page.getTotalCount();
}
cartes = cartes.subList(page.getBeginIndex(), endIndex);
ServletActionContext.getRequest().setAttribute("cartes", cartes);
ServletActionContext.getRequest().setAttribute("page", page);
return this.SUCCESS;
}
package com.qddx.wmal.dao.impl;
public class Page {
private int everyPage; // 每页显示数量
private int totalCount; // 总记录数
private int totalPage; // 总页数
private int currentPage; // 当前页码
private int beginIndex; // 起始点
private boolean hasPrePage; // 是否有上一页
private boolean hasNextPage; // 是否有下一页
public Page(int everyPage, int totalCount, int totalPage, int currentPage,
int beginIndex, boolean hasPrePage, boolean hasNextPage) {
super();
this.everyPage = everyPage;
this.totalCount = totalCount;
this.totalPage = totalPage;
this.currentPage = currentPage;
this.beginIndex = beginIndex;
this.hasPrePage = hasPrePage;
this.hasNextPage = hasNextPage;
}
public Page() {
}
public int getEveryPage() {
return everyPage;
}
public void setEveryPage(int everyPage) {
this.everyPage = everyPage;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getBeginIndex() {
return beginIndex;
}
public void setBeginIndex(int beginIndex) {
this.beginIndex = beginIndex;
}
public boolean isHasPrePage() {
return hasPrePage;
}
public void setHasPrePage(boolean hasPrePage) {
this.hasPrePage = hasPrePage;
}
public boolean isHasNextPage() {
return hasNextPage;
}
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}
}
PageUtil.java
package com.qddx.wmal.dao.impl;
public class PageUtil {
public static Page createPage(int everyPage, int totalCount, int currentPage) {
//每页记录数
everyPage = getEveryPage(everyPage);
//当前页
currentPage = getCurrentPage(currentPage);
//总页数
int totalPage = getTotalPage(everyPage, totalCount);
//起始点
int beginIndex = getBeginIndex(everyPage, currentPage);
//是否有上一页
boolean hasPrePage = getHasPrePage(currentPage);
//是否有下一页
boolean hasNextPage = getHasNextPage(totalPage, currentPage);
return new Page(everyPage, totalCount, totalPage, currentPage,
beginIndex, hasPrePage, hasNextPage);
}
//得到当前页记录数
public static int getEveryPage(int everyPage){
return everyPage;
}
//得到当前页码
public static int getCurrentPage(int currentPage){
return currentPage == 0 ? 1 : currentPage;
}
//得到总页数
public static int getTotalPage(int everyPage, int totalCount){
int totalPage = 0;
if(totalCount % everyPage == 0){
totalPage = totalCount/everyPage;
}else{
totalPage = totalCount/everyPage + 1;
}
return totalPage;
}
//得到每页起始点
public static int getBeginIndex(int everyPage, int currentPage){
return (currentPage - 1) * everyPage;
}
//是否上一页
public static boolean getHasPrePage(int currentPage){
return currentPage == 1 ? false : true;
}
//是否有下一页
public static boolean getHasNextPage(int totalPage, int currentPage){
return totalPage == currentPage || totalPage == 0 ? false : true;
}
}
Action.java
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getCurrentPage() {
return currentPage;
}
public String showCartes() throws Exception{
List<Carte> cartes = carteHibernate.findByRes((Res) session.get("res"));
Page page = PageUtil.createPage(everyPage, cartes.size(), currentPage);
int endIndex = page.getBeginIndex() + page.getEveryPage();
if(endIndex > page.getTotalCount()){
endIndex = page.getTotalCount();
}
cartes = cartes.subList(page.getBeginIndex(), endIndex);
ServletActionContext.getRequest().setAttribute("cartes", cartes);
ServletActionContext.getRequest().setAttribute("page", page);
return this.SUCCESS;
}
0 0
- Page分页
- Page分页
- Page分页
- 分页page
- js--page--分页--
- page 分页的源代码
- 分页 Page 类
- PHP分页类Page
- 分页控件page源码
- page标签分页
- java分页类Page
- page 分页 java
- jquery.page.js分页
- page.jsp 分页
- Page分页类
- rails find_by_sql page分页
- java page-taglib分页
- page 简单易懂 分页
- layoutSubviews总结
- World Wind Java开发之十四——添加WMS地图服务资源
- warning:performSelector may cause a leak because its selector
- HTTP POST GET 本质区别详解
- android调用webservice接口应用实例
- Page分页
- OC面向对象编程基础总结
- android 开发工具集合
- hdu 1227 简单dp+中位数的性质
- 彻底解决INSTALL_FAILED_UPDATE_INCOMPATIBLE的安装错误
- 图的深度优先搜索/广度优先搜索(邻接表实现)
- 大批量数据导入数据库,dbf导入oracle,csv导入oracle
- Linux系统安装
- Notification的使用以及实现效果