pagecontroller.java

来自「基于Sturts+Spring+Hibernate的一个高级销售管理系统。内容丰」· Java 代码 · 共 129 行

JAVA
129
字号
package com.yuanchung.sales.util;

import java.util.ArrayList;
import java.util.Collection;

public class PageController {
	private int currentPage; //当前页码

	private int pageCount;//每页记录数

	private String path;//查询路径

	private int allCount;//总记录数

	private Collection items;//查询的数据集
    
	private Collection currentItems;//当前页结果集
	
	private String pageBar;
	
	public Collection getCurrentItems() {		
		return currentItems;
	}	
	public void setCurrentItems(int currentPage) {
//		Collection currentItems = null;
		this.currentPage = currentPage;
//		currentItems = new ArrayList();
//    	ArrayList al = (ArrayList)items;
//        if(currentPage < (allCount / pageCount) + 1){        	
//        	for(int i = (currentPage - 1) * pageCount; i < currentPage * this.pageCount; i++){
//        		currentItems.add(al.get(i));
//        	}
//		}else{
//			for(int i = (currentPage - 1) * pageCount; i < allCount; i++){
//        		currentItems.add(al.get(i));
//        	}
//		}
		this.currentItems = items;
	}
	public PageController(){}
	public PageController(String path, int allCount, int currentPage, int pageCount, Collection items ){
		this.path = path;
		this.allCount = allCount;
		this.currentPage = currentPage;
		this.pageCount = pageCount;
		this.items = items;
	}
	
	public int getAllCount() {
		return allCount;
	}

	public void setAllCount(int allCount) {
		this.allCount = allCount;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int count) {
		this.pageCount = count;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public Collection getItems() {
		return items;
	}

	public void setItems(Collection items) {
		this.items = items;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	public int getAllPage(){
		if(this.allCount % this.pageCount == 0){
			return (this.allCount)/this.pageCount;
		}else{
			return (this.allCount)/this.pageCount+1;
		}
	}
	public void setPageBar(){
		StringBuffer bar = new StringBuffer();
		bar.append("<%@ page language='java' pageEncoding='UTF-8'%>");
		bar.append("<div class='tableHead'>");
		if(this.currentPage<=1){
			bar.append("首页&nbsp;&nbsp;&nbsp;上页&nbsp;&nbsp;&nbsp;");
		}else{
			bar.append("<a href=\"javascript:searchByPage(1)\">首页</a>&nbsp;&nbsp;&nbsp;");
			bar.append("<a href=\"javascript:searchByPage("+this.currentPage+"-1)\">上页</a>&nbsp;&nbsp;&nbsp;");
		}
		bar.append("&nbsp;&nbsp;&nbsp;<select  name=\"xx\" onchange=\"searchByPage(this.value)\">");
		for(int i=1;i<=this.getAllPage();i++){
			if(i==this.currentPage){
				bar.append("<option value='"+i+"' selected>"+i+"/"+this.getAllPage()+"</option>");
			}else{
				bar.append("<option value='"+i+"'>"+i+"/"+this.getAllPage()+"</option>");
			}
		}
		bar.append("</select></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
		if(this.currentPage>=this.getAllPage()){
			bar.append("下页&nbsp;&nbsp;&nbsp;尾页");
		}else{
			bar.append("<a href=\"javascript:searchByPage("+this.currentPage+"+1)\">下页</a>&nbsp;&nbsp;&nbsp;");
			bar.append("<a href=\"javascript:searchByPage("+this.getAllPage()+")\">尾页</a>");
		}		
		bar.append("<span align=\"left\" style='margin-left:10px'>每页"+this.pageCount+"条/共"+this.getAllPage()+"页   共"+this.allCount+"条</span></div>");
		
		this.pageBar = bar.toString();		
	}
	public String getPageBar(){
		return this.pageBar;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?