JSP分页类一:SplitPageVo
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
public class SplitPageVo {
private List data;// 数据
private String url;// 跳转的URL地址
private SqlVo sqlVo;
private PageVo pageVo;
public SqlVo getSqlVo() {
return sqlVo;
}
public void setSqlVo(SqlVo sqlVo) {
this.sqlVo = sqlVo;
}
public void setSqlVo(String table, String where, String order,String point) {
this.sqlVo = new SqlVo( table, where, order, point);
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
if (url.indexOf("?") < 0) {
this.url = url + "?page=";
} else {
this.url = url + "&page=";
}
}
public List getData() {
return data;
}
public void setData(List data) {
this.data = data;
}
public PageVo getPageVo() {
return pageVo;
}
public void setPageVo(PageVo pageVo) {
this.pageVo = pageVo;
}
public void setPageVo(int _page,int _count,int _preList) {
this.pageVo = new PageVo(_page,_count,_preList);
}
public void setPageVo(int _page,int _preList) {
this.pageVo = new PageVo(_page,_preList);
}
public int getTop1() {
int top1;
if(this.pageVo.getCount()>=this.getTop2()){
top1=this.pageVo.getPreList();
}else{
top1=this.pageVo.getCount()%this.pageVo.getPreList();
}
//System.out.println(top1);
return top1;
}
public int getTop2() {
int top2;
top2=this.pageVo.getNowPage()*this.pageVo.getPreList();
return top2;
}
//求出所有信息条数
public void getCount(Connection _conn){
////定义 PreparedStatement
PreparedStatement ps = null;
//定义数据库链接
Connection conn = null;
//第一结果集
ResultSet rs=null;
try{
conn=_conn;
//获得 数据库 prepareStatement
ps = conn.prepareStatement(this.sqlVo.toCountSql());
// System.out.println(this.sqlVo.toCountSql());
//执行SQL
rs = ps.executeQuery();
while(rs.next()){
this.getPageVo().setCount(rs.getInt("count"));
}
//System.out.println(this.getPageVo().getCount());
}catch (Exception ex)
{
ex.printStackTrace();
}finally{
try{
//关闭 ps
if (ps != null)
{
ps.close();
ps = null;
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
public String splitPage() {
StringBuffer sbStr = new StringBuffer();
sbStr.append("第 " + this.getPageVo().getNowPage() + " 页 / 共 " + this.getPageVo().getTotalPage()
+ " 页");
sbStr.append(" ");
if (this.getPageVo().getNowPage() == 1) {
sbStr.append(" 首页 ");
} else {
sbStr.append("<A HREF='" + this.getUrl() + this.getPageVo().getFirstPage()
+ "'> 首页 </A>");
}
sbStr.append(" ");
if (this.getPageVo().getNowPage() == 1) {
sbStr.append(" 上一页 ");
} else {
sbStr.append("<A HREF='" + this.getUrl() + this.getPageVo().getPrePage()
+ "'> 上一页 </A>");
}
sbStr.append(" ");
if (this.getPageVo().getNowPage() == this.getPageVo().getTotalPage()) {
sbStr.append(" 下一页 ");
} else {
sbStr.append("<A HREF='" + this.getUrl() + this.getPageVo().getNextPage()
+ "'> 下一页 </A>");
}
sbStr.append(" ");
if (this.getPageVo().getNowPage() == this.getPageVo().getTotalPage()) {
sbStr.append(" 尾页 ");
} else {
sbStr.append("<A HREF='" + this.getUrl() + this.getPageVo().getLastPage()
+ "'> 尾页 </A>");
}
return sbStr.toString();
}
}