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

📄 mysqlmultipage.java

📁 分页,mysql,可重用性,有多种形式的
💻 JAVA
字号:
package com.mgie.pkmm.util.mysqlPage;

import com.mgie.pkmm.util.Per_home_admin_properties;

/**
 * @author MG-小华仔
 *This bean is to pagination like <<上x页  1|2|3|4|5 ....x  >>下x页
 */
public class MysqlMultiPage implements MysqlPageImp{

		int start_page=0;//页数开始的显示
	    int show_page=5;//每次显示多少页 如:<<上5页 1|2|3|4|5 >>下5页
		int start_num=0;//
		int per_page =10; //每页显示的数量
		int total_page=0;//总页数 
		int end_page=start_page+show_page-1;//页数显示的结束

	    int page=0; //当前页数
	    int jump_page=0;
	    
	    int mytotal_page;//自定义总页数
		boolean hasNextPage = false; // 是否有下一页
		boolean hasPreviousPage = false; // 是否有前一页
		String actionLink="";
		
	    public MysqlMultiPage(){
	    	
	    }
	    
	    public MysqlMultiPage(int total_page, int per_page,int show_page,String actionLink)
	    {
			if(total_page>0)
			{
				if(total_page%per_page==0)
					this.total_page=total_page/per_page;
				else
					this.total_page=total_page/per_page+1;
			}
			System.out.println("___________totalpage is :"+this.getTotal_page()+" "+this.total_page);
			if(mytotal_page<total_page&&mytotal_page!=0)
				mytotal_page=total_page;
			
			this.per_page = per_page;
			this.show_page = show_page;
			
			this.actionLink = actionLink;
		   this.start_page = 0;//页数开始的显示
			this.start_num = 0;

			this.end_page=this.start_page+this.show_page-1;//页数显示的结束
			this. page = 0; //当前页数
			this.jump_page=0;
	    }
 /***=========================Contorl part =========================****/
		public void init(int total_page, int per_page,int show_page,String actionLink) {
			// TODO Auto-generated method stub
			if(total_page>0)
			{
				if(mytotal_page<total_page&&mytotal_page!=0)
					total_page=mytotal_page;

				if(total_page%per_page==0)
					this.total_page=total_page/per_page;
				else
					this.total_page=total_page/per_page+1;
			}
			
			this.actionLink = actionLink;
			this.per_page = per_page;
			this.show_page = show_page;
		}
		public void jumpPage(int jump_page) {
			// TODO Auto-generated method stub

			if(jump_page<=0){
				page=0;
				start_page=0;
				end_page=show_page-1;
			}
			else if(jump_page>total_page){
				page = total_page-1;
				end_page = total_page-1;
				start_page =(total_page-1)-end_page%show_page;
			}
			else 
			{
				page = jump_page-1;
				this.jump_page = jump_page;
				

				//输入的页数是show_page 的倍数
				if(page%(show_page)==0&&page!=0)
					start_page=show_page;
				else{
					start_page = page-page%(show_page);
				}

					
				if(start_page<show_page-1)
				{
					start_page=0;
					if(total_page>show_page)
						end_page=show_page-1;
					else
						end_page=total_page-1;
				}
				else
				{
					end_page=start_page+show_page-1;
					if(end_page>total_page-1)
						end_page=total_page-1;
				}
				//end_page=start_page+show_page-1;
			}

			start_num = (page * per_page);
			
		}
		public void nextPage() {
			// TODO Auto-generated method stub
			if ((total_page-(start_page+show_page)>0)&&(total_page-(start_page+show_page)<=show_page))
			{
				end_page = total_page-1;
				this.hasNextPage=false;
				start_page = start_page+show_page;
				
				start_num = (start_page * per_page);
				page = start_page;
			}
			else if((total_page-(start_page+show_page)>0)&&(total_page-(start_page+show_page)>show_page))
			{
				end_page = end_page +5;
				this.hasNextPage=true;
				start_page = start_page+show_page;
				
				start_num = (start_page * per_page);
				page = start_page;
			}
			

/*				System.out.println("the page "+page+" total "+total_page);
			if ((total_page-(start_page+show_page)>0)&&(total_page-(start_page+show_page)<=show_page))
				end_page = total_page-1;
			else if((total_page-(start_page+show_page)>0)&&(total_page-(start_page+show_page)>show_page))
				end_page = end_page +5;
			
			if (page + 1 < total_page)
			{
				
				this.hasNextPage=false;
				if(start_page+show_page<end_page&&start_page+show_page<total_page-1)
				start_page = start_page+show_page;
				
				start_num = (start_page * per_page);
				page = start_page;
			}*/
			
		}
		public void prvPage() {
			// TODO Auto-generated method stub
			if(total_page<show_page)
				end_page = total_page;
			else
				end_page = start_page-1;
			start_page=start_page-show_page;
			
			if (start_page < 0)
			{
				start_page = 0;
				start_num = 0;

				if(total_page<show_page)
					end_page = total_page;
				else
					end_page=show_page;
			}						
			start_num = (start_page * per_page);
			
			
			page = start_page;
		}

		public void description() {

			String description =

			" 共有页数: " + this.getTotal_page() +

			" 当前页数为:" + this.getPage() +

			" 是否有前一页: " + this.isHasPreviousPage() +

			" 是否有下一页:" + this.isHasNextPage() +

			" 开始行数:" + this.getStart_num() +

			" 显示页数: "+this.getShow_page()+
			
			" 开始页数: "+this.getStart_page()+
			
			" 结束页数: "+this.getEnd_page()+
			
			" 每页显示:" + this.getPer_page();

			

		}
		
		public String getLinkcode()
		{
			
				String code=this.getPage()+"/"+this.getTotal_page()+Per_home_admin_properties.page+"&nbsp;&nbsp;";
				String prvpageLink="<上 "+show_page+Per_home_admin_properties.page;
				String prvlinkString="<a href='"+actionLink+"&action=prvPage'><上"+show_page+Per_home_admin_properties.page+"</a>";
				String nextpageLink="下 "+show_page+Per_home_admin_properties.page+">";
				String nextlinkString="<a href='"+actionLink+"&action=nextPage'>下 "+show_page+Per_home_admin_properties.page+"></a>";
				String jumppageLink="";
				
				String javascript="<script>function jump(){var a= document.getElementById('jumpBox').value;window.location='"+actionLink+"&action=jumpPage&jumpPage='+a;}</script>";


				String inputBox="<input type='text' id='jumpBox' name='jumpBox' value=0 onpropertychange="+'"'+"if(/\\D/g.test(value))value=value.replace(/\\D/g,'')"+'"' +"style='ime-mode:disabled' ondragenter='return false' maxlength=9 size=9>";
				
				String jumpBt="<input type='button' name='jumpBt' value='跳转' onclick='jump()'>";


				if (this.isHasPreviousPage())
				{
					prvpageLink=prvlinkString;
				}		
				if(this.isHasNextPage())
				{
					nextpageLink=nextlinkString;
				}

				System.out.println("____________"+this.getStart_page()+"   endpage"+this.getEnd_page());
				for(int i=this.getStart_page();i<=this.getEnd_page();i++)
				{
					if(i!=this.getPage())
					{
						jumppageLink=jumppageLink+"<a href ='"+actionLink+"&action=jumpPage&jumpPage="+i+"'>"+ i +"</a>|";
					}
					else
					{
						jumppageLink=jumppageLink+"<font color='red'>"+this.getPage()+"</font>|";
					}
					
				}
				code =code+ prvpageLink+"&nbsp;"+jumppageLink+"&nbsp;"+nextpageLink;//+" &nbsp;"+inputBox+" &nbsp;"+jumpBt+javascript;
			return code;
		}
		
		
		public String getLinkcode_script()
		{
			String url=actionLink;
			String str="";
			String type="";
			String actionLink_prvPage="";
			String actionLink_nextPage="";
			String actionLink_jumpPage="";
			if(url.indexOf("china")!=-1){
				str=url.substring(url.indexOf("china")+5);
				url=url.substring(0,url.indexOf("china")+5);
				
			}
			actionLink_prvPage="<a href='#' onclick="+'"'+"getLinkcode_script('"+actionLink+"','&action=prvPage')"+'"'+">";
			actionLink_nextPage="<a href='#' onclick="+'"'+"getLinkcode_script('"+actionLink+"','&action=pnextPage')"+'"'+">";
			
			
				String code=this.getPage()+"/"+this.getTotal_page()+Per_home_admin_properties.page+"&nbsp;&nbsp;";
				String prvpageLink="<上 "+show_page+Per_home_admin_properties.page;
				String prvlinkString=actionLink_prvPage+"<上"+show_page+Per_home_admin_properties.page+"</a>";
				String nextpageLink="下 "+show_page+Per_home_admin_properties.page+">";
				String nextlinkString=actionLink_nextPage+"下 "+show_page+Per_home_admin_properties.page+"></a>";
				String jumppageLink="";
				
				String javascript="<script>function jump(){var a= document.getElementById('jumpBox').value;window.location='"+actionLink+"&action=jumpPage&jumpPage='+a;}</script>";


				String inputBox="<input type='text' id='jumpBox' name='jumpBox' value=0 onpropertychange="+'"'+"if(/\\D/g.test(value))value=value.replace(/\\D/g,'')"+'"' +"style='ime-mode:disabled' ondragenter='return false' maxlength=9 size=9>";
				
				String jumpBt="<input type='button' name='jumpBt' value='跳转' onclick='jump()'>";


				if (this.isHasPreviousPage())
				{
					prvpageLink=prvlinkString;
				}		
				if(this.isHasNextPage())
				{
					nextpageLink=nextlinkString;
				}

				System.out.println("____________"+this.getStart_page()+"   endpage"+this.getEnd_page());
				for(int i=this.getStart_page();i<=this.getEnd_page();i++)
				{
					if(i!=this.getPage())
					{
						actionLink_jumpPage="<a href='#' onclick="+'"'+"getLinkcode_script('"+actionLink+"','&action=jumpPage&jumpPage="+i+"')"+'"'+">";
						jumppageLink=jumppageLink+actionLink_jumpPage+ i +"</a>|";
					}
					else
					{
						jumppageLink=jumppageLink+"<font color='red'>"+this.getPage()+"</font>|";
					}
					
				}
				code =code+ prvpageLink+"&nbsp;"+jumppageLink+"&nbsp;"+nextpageLink;//+" &nbsp;"+inputBox+" &nbsp;"+jumpBt+javascript;
			return code;
		}
		
		
		//======================================================
		public int getEnd_page() {
			if(end_page<show_page&&total_page<=show_page)
				return end_page=total_page;
			else
				return end_page+1;
		}

		public void setEnd_page(int end_page) {
			this.end_page = end_page;
		}

		public int getMytotal_page() {
			return mytotal_page;
		}

		public void setMytotal_page(int mytotal_page) {
			this.mytotal_page = mytotal_page;
		}

		public int getPage() {
			return page+1;
		}

		public void setPage(int page) {
			this.page = page;
		}

		public int getPer_page() {
			return per_page;
		}

		public void setPer_page(int per_page) {
			this.per_page = per_page;
		}

		public int getShow_page() {
			return show_page;
		}

		public void setShow_page(int show_page) {
			this.show_page = show_page;
		}

		public int getStart_num() {
			return start_num;
		}

		public void setStart_num(int start_num) {
			this.start_num = start_num;
		}

		public int getStart_page() {

			return start_page+1;
		}

		public void setStart_page(int start_page) {
			this.start_page = start_page;
		}

		public int getTotal_page() {
			return total_page;
		}

		public void setTotal_page(int total_page) {
			this.total_page = total_page;
		}

		public boolean isHasNextPage() {
			
			if(end_page>0 && end_page<total_page-1 && total_page>show_page)
				return hasNextPage = true;
			else			
			    return hasNextPage=false;
		}

		public void setHasNextPage(boolean hasNextPage) {
			this.hasNextPage = hasNextPage;
		}

		public boolean isHasPreviousPage() {
			
			if(total_page>show_page && total_page>=end_page && start_page>=show_page)
				return hasPreviousPage = true;
			else
				return hasPreviousPage = false;
		}

		public void setHasPreviousPage(boolean hasPreviousPage) {
			this.hasPreviousPage = hasPreviousPage;
		}

		public int getJump_page() {
			return jump_page;
		}

		public void setJump_page(int jump_page) {
			this.jump_page = jump_page;
		}

		public String getActionLink() {
			return actionLink;
		}

		public void setActionLink(String actionLink) {
			this.actionLink = actionLink;
		}
	    
}

⌨️ 快捷键说明

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