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

📄 xpage.java

📁 一套购物车项目。电子商务系统。实现了前台和后台的业务逻辑。
💻 JAVA
字号:
package com.softfz.jn0708.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 页面 分页 
 * @author student
 *
 */
public class XPage {

	private int count;

	private int currentPage;

	private int allcount;
	
	private String path;
	
	public XPage(int currentPage,int count,String sql){
		this.currentPage = currentPage;
		this.count= count;
		Connection conn = null;
		Statement st = null;
		ResultSet rs = null;
		conn = SqlUtil.getConn();
		try {
			st = conn.createStatement();
			rs = st.executeQuery(sql);
			if(rs.next()){
				this.allcount = rs.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			SqlUtil.tryClose(rs,st,conn);
		}
	
	}

	public int getAllcount() {
		return allcount;
	}

	public void setAllcount(int allcount) {
		this.allcount = allcount;
	}

	public int getCount() {
		return count;
	}

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

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	
	public int getAllPage(){
		return (this.allcount-1)/this.count+1;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	public String getPageBar(){
		StringBuffer bar = new StringBuffer();
		
		bar.append("<%");
		bar.append("String contextPath = request.getContextPath();");
		bar.append("%>");
		bar.append("<link href='<%=contextPath%>/css/css.css' type='text/css' rel='stylesheet' />");		
		bar.append("<tr border='0'>");
		bar.append("<div class='tableHead'><span align=\"left\" style='margin-left:10px'>当前"+this.currentPage+"/"+this.getAllPage()+"共"+this.allcount+"条记录</span>");
		bar.append("<span align=right style='margin-right:10px;margin-left:100px'>");
		if(this.currentPage<=1){
			bar.append("首页&nbsp;&nbsp;&nbsp;上页&nbsp;&nbsp;&nbsp;");
		}else{
			bar.append("<a href=\""+path+"currentPage=1\">首页</a>&nbsp;&nbsp;&nbsp;");
			bar.append("<a href=\""+path+"currentPage="+(this.currentPage-1)+"\">上页</a>&nbsp;&nbsp;&nbsp;");
		}
		
		if(this.currentPage>=this.getAllPage()){
			bar.append("下页&nbsp;&nbsp;&nbsp;尾页");
		}else{
			bar.append("<a href=\""+path+"currentPage="+(this.currentPage+1)+"\">下页</a>&nbsp;&nbsp;&nbsp;");
			bar.append("<a href=\""+path+"currentPage="+(this.getAllPage())+"\">尾页</a>");
		}
		
		
		bar.append("&nbsp;&nbsp;&nbsp;<select name=\"page\" onchange=\"forward(this.value)\">");
		for(int i=1;i<=this.getAllPage();i++){
			if(i==this.currentPage){
				bar.append("<option value='"+i+"' selected>"+i+"</option>");
			}else{
				bar.append("<option value='"+i+"'>"+i+"</option>");
			}
			
		}
		bar.append("</select></span></div>");
		bar.append("</tr>");
		
		bar.append("<script>");
		bar.append("function forward(page){")
		.append(" location.href='"+path+"currentPage='+page;")
		.append("}");
		bar.append("</script>");
		return bar.toString();
	}

}

⌨️ 快捷键说明

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