⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractpagination.java

📁 基于struts+hibernate的电子商务网站。可运行。数据库mysql
💻 JAVA
字号:
package tarena.data;

import java.util.List;

/**
 * 分页抽象类
 *
 */
@SuppressWarnings("unchecked")
public abstract class AbstractPagination {
	/**
	 * 总记录数,默认为0
	 */
	private int total = 0;
	
	/**
	 * 每页显示的记录数,默认为1
	 */
	private int every = 1;
	
	/**
	 * 当前页数,默认为1
	 */
	private int current = 1;
	
	/**
	 * 当前URL,默认为空
	 */
	private String url = null;
	
	/**
	 * 分页参数的名称,默认为page
	 */
	private String param = "page";	 
	
		
		
	public AbstractPagination(){}


	public AbstractPagination(int total, int every, int current, String url) {
		super();
		this.total = total<0?0:total;
		this.every = every<1?1:every;		
		this.current = (current>=1&&current<=this.getTotalPage())?current:1;
		this.url = url;
	}

	

	public AbstractPagination(int total, int every, int current, String url,String param) {
		super();
		this.total = total<0?0:total;
		this.every = every<1?1:every;
		this.current = (current>=1&&current<=this.getTotalPage())?current:1;
		this.url = url;
		this.param = param==null?this.param:param;
	}


	public int getTotal() {
		return total;
	}


	public void setTotal(int total) {
		this.total = total<0?0:total;
	}


	public int getEvery() {
		return every;
	}


	public void setEvery(int every) {
		this.every = every<1?1:every;
	}


	public int getCurrent() {
		return current;
	}


	public void setCurrent(int current) {
		this.current = (current>=1&&current<=this.getTotalPage())?current:1;
	}


	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	};
	
	public String getParam() {
		return this.param==null?"page":this.param;
	}

	public void setParam(String param) {
		this.param = param==null?this.param:param;
	}
	
	/**
	 * 得到总页数
	 * @return
	 */
	public int getTotalPage(){
		return total%every==0?total/every:((total/every)+1);
	}
	
	/**
	 * 得到指定页面的URL,使用正则表达式替换掉page参数
	 * @param page
	 * @return
	 */
	public String getURLByPage(int page){
		String url = this.getUrl();
		String regex = this.getParam()+"=\\d?";
		String replace = this.getParam()+"="+page;
		if(url == null) return null;
		if(!url.contains(this.getParam()+"=")){
			if(!url.contains("?")){
				return url.concat("?"+replace);
			}
			return url.concat("&"+replace);
		}
		return url.replaceAll(regex,replace);
	}

	/**
	 * 得到首页
	 * @return
	 */
	public abstract Page getFirst(String pageName);
	
	/**
	 * 得到末页
	 * @return
	 */
	public abstract Page getLast(String pageName);
	
	/**
	 * 得到前一页
	 * @return
	 */
	public abstract Page getPrevious(String pageName);
	
	/**
	 * 得到下一页
	 * @return
	 */
	public abstract Page getNext(String pageName);
	
	/**
	 * 得到所有页面
	 * @return
	 */
	public abstract List<Page> getContent();
}

⌨️ 快捷键说明

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