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

📄 page.java

📁 这是一个网上书站的例子
💻 JAVA
字号:
package com.zxf.page;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;

import com.db.Jdo;


public class Page {
	public String pageIndex(int row,int column,int pageIndex,String table,ShowKind kind,String sql)//
	{
		Jdo jdo=new Jdo();
		int totalCount=jdo.rowCount("select count(*) from "+table+" "+sql);
		int pageCount=row*column;
		int totalIndex;
		StringBuffer html=null;
		totalIndex=(int)Math.ceil((double)totalCount/(double)pageCount);//总页数
		if(pageIndex>totalIndex||pageIndex<=0)
		{
			//System.out.print("不存在这在的页");
			return "没有任何记录!!";
		}
		else if(pageIndex==totalIndex)//显示最后一页
		{
			int fromSize=(pageIndex-1)*pageCount;
			int size=totalCount-fromSize;
			int currentPageCount=totalCount-fromSize;//最后一页的数据
			int lastPageRow=(int)Math.ceil((double)currentPageCount/(double)column);//最后一页数据的行数
			int allRow=lastPageRow-1;//前N-1行正常输出
			int lastRow=currentPageCount-allRow*column;
			ResultSet rs=jdo.executeQuery("select * from "+table+" "+sql+" LIMIT "+fromSize+","+size);
			
			PageShow pageShow=new PageShow();
			html=pageShow.showLastPage(rs, column, allRow, lastRow, totalIndex,kind);
		}
		else if(pageIndex<totalIndex)
		{
			int fromSize=(pageIndex-1)*pageCount;
			int size=pageCount;
			ResultSet rs=jdo.executeQuery("select * from "+table+" LIMIT "+fromSize+","+size);
			
			PageShow pageShow=new PageShow();
			html=pageShow.showMidddlePage(rs, column, row, totalIndex, kind);
			
		}
		jdo.destroy();
		return html.toString();
	}
	public static void main(String args[]) throws SQLException//test,可以去掉
	{
		
		Page page=new Page();
		Page showpage=new Page();
	   	String str=showpage.pageIndex(6,1,1,"user",new ShowKindAdminUser(),"");
		//String html=page.pageIndex(3,2,Integer.parseInt("1"),"bigcatalog",new ShowKindIndexBook(),"");//"where smallcatalogid="+"1");
		System.out.println(str);
		
	}

}

⌨️ 快捷键说明

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