• 分页问题


    public class DaoUtil{
    	/**
    	 * 分页条
    	 * @param total
    	 * @param size //每页记录数
    	 * @param page //当前页
    	 * @param all //总页数
    	 * @param cmd
    	 * @param where //查询条件
    	 * @param params
    	 * @return
    	 */
    	public static String getPagination(int total, int size, int page, int all, String cmd, String where, String params){
    		StringBuffer bf = new StringBuffer();
    		String first = "disabled";
    		String previous = "disabled";
    		String next = "disabled";
    		String last = "disabled";
    		String message = "";
    		String readonly = "";
    		if(total>0){
    			if(total>size){
    				if(page==1){
    					next = "onclick=btnclick('next');";
    					last = "onclick=btnclick('last');";
    				}else if(page>1 && page<all){
    					first = "onclick=btnclick('first')";
    					previous = "onclick=btnclick('previous')";
    					next = "onclick=btnclick('next');";
    					last = "onclick=btnclick('last');";
    				}else {
    					first = "onclick=btnclick('first')";
    					previous = "onclick=btnclick('previous')";
    				}
    				int begin = size*(page-1)+1;
    				int end = size*page;
    				if(page==all){
    					end = total;
    				}
    				message = "<span class='spanbar spanlabel'>当前显示 "+begin+" - "+end+" 条记录</span>"+"<span class='spanbar spanlabel'> / 共 "+total+" 条记录</span>";
    			}else {
    				readonly = "disabled";
    				message = "<span class='spanbar spanlabel'>当前显示 1 - "+total+" 条记录</span>"+"<span class='spanbar spanlabel'> / 共 "+total+" 条记录</span>";
    			}
    		}else {
    			readonly = "disabled";
    			message = "当前没有可以显示的数据";
    		}
    		bf.append("<style type="text/css">.spanbar{margin-right: 8px;}.spanlabel{font-size: 13px;}</style>");
    		bf.append("<table width="100%" height='30' border="0" cellpadding="0" cellspacing="0"><tr><td align='right'>")
    			.append("<div style='margin-right: 10%'><span class='spanbar spanlabel'>")
    			.append("<a href='javascript:;' ").append(first).append(">首  页</a></span>")
    			.append("<span class='spanbar spanlabel'><a href='javascript:;' ").append(previous).append(">上一页</a></span>")
    			.append("<span class='spanbar'><img src='../tbs_img/grid-split.gif' border='0' /></span>")
    			.append("<span class='spanbar spanlabel'>页</span>")
    			.append("<input type="text" id="pageText" ").append(readonly).append(" onfocus=this.style.imeMode='disabled';")
    			.append(" style='24px; font-size:11px; border:1px solid #999;' value="").append(page).append("" /><span class='spanbar' style='margin-left: 8px;'>/</span>")
    			.append("<span class='spanbar spanlabel'>").append(all).append("</span><span class='spanbar'><img src='../tbs_img/grid-split.gif' border='0' /></span>")
    			.append("<span class='spanbar spanlabel'><a href='javascript:;' ").append(next).append(">下一页</a></span>")
    			.append("<span style='margin-right: 50px;' class='spanlabel'><a href='javascript:;' ").append(last).append(">末  页</a></span>")
    			.append(message).append("</div></td></tr></table>");
    		bf.append("<input type="hidden" id="pageNum" name='pageNum' value='").append(page).append("' />");
    		bf.append("<input type="hidden" id="pageType" name="pageType" />");
    		bf.append("<input type="hidden" id="pageWhere" name="pageWhere" value="").append(where).append("" />");
    		bf.append("<script>function btnclick(obj){var frmMain=$$$('frmMain');frmMain.cmd.value='").append(cmd).append("';frmMain.pageType.value=obj;")
    			.append("frmMain.init.value='page';").append(params).append("getParams('frmMain');frmMain.target='_self';frmMain.submit();};")
    			.append("function btnKeyDown(){if(event.keyCode==13){var n=$$$('pageText').value;if(n!=''&&n!=").append(page).append("){if(n>")
    			.append(all).append("){n=").append(all).append(";};if(n<1){n=1;};$$$('pageNum').value=n;btnclick('');}else{return false;}}}</script>");
    		return bf.toString();
    	}
    	
    	/**
    	 * 分页条
    	 * @param total 总记录
    	 * @param size 每页记录
    	 * @return
    	 */
    	public static String getPagination2(int total, int size, int page) {
    		StringBuffer s = new StringBuffer();
    		int maxPage=1;
    		if (total > 0) {
    			maxPage = total<size?1:total/size+(total%size>0?1:0);
    		}
    		s.append("<style type='text/css'>");
    		s.append(".p_bar{margin-right: 8px;};");
    		s.append(".p_label{font-size: 14px;};");
    		s.append("</style>");
    		s.append("<table width='100%' height='30' border='0' cellpadding='0' cellspacing='0' align='center' style='cursor:default;'><tr><td width='55%' align='right'>");
    		s.append("<span class='p_bar p_label'><a id='page_first' href='javascript:;' onclick='p_btn_click(this)'"+(page>1?"":" disabled")+">首  页</a></span>");
    		s.append("<span class='p_bar p_label'><a id='page_previous' href='javascript:;' onclick='p_btn_click(this)'"+(page>1?"":" disabled")+">上一页</a></span>");
    		s.append("<span class='p_bar'><img src='../tbs_img/grid-split.gif' border='0' /></span>");
    		s.append("<span class='p_bar p_label'>页</span>");
    		s.append("<input type='text' id='pageText' style='30px;border:1px solid #999;font-size:13px;' maxlength='"+String.valueOf(maxPage).length()+"' onfocus="this.style.imeMode='disabled';" "
    				+ ((maxPage > 1) ? "" : "disabled")
    				+ " onKeyPress='if(event.keyCode<48||event.keyCode>57)event.returnValue=false;' value='"+page+"' />");
    		s.append("<span id='page_go' class='p_bar p_label' style='margin-left: 10px; cursor: pointer; color:red;' "
    				+ ((maxPage > 1) ? "onclick='p_btn_click(this)'" : "disabled") + ">跳转</span>");
    		s.append("<span class='p_bar'>/</span>");
    		s.append("<span id='p_total' class='p_bar p_label'>"+maxPage+"</span><span class='p_bar'><img src='../tbs_img/grid-split.gif' border='0' /></span>");
    		s.append("<span class='p_bar p_label'><a id='page_next' href='javascript:;'"
    				+ ((maxPage > 1 && page < maxPage) ? "" : " disabled") + " onclick='p_btn_click(this)'>下一页</a></span>");
    		s.append("<span class='p_label'><a id='page_last' href='javascript:;'"
    				+ ((maxPage > 1 && page < maxPage) ? "" : " disabled") + " onclick='p_btn_click(this)'>末  页</a></span>");
    		s.append("</td><td width='45%' align='center'>");
    		s.append("<table border='0' cellpadding='0' cellspacing='0' width='320' id='p_data_full' class='p_bar p_label'"
    				+ (total > 0 ? "" : " style='display:none;'")
    				+ "><tr><td width='65' align='center'>当前显示</td><td width='35' align='right'><span id='p_start'>"+((page-1)*size+1)+"</span></td><td width='10' align='center'>-</td><td width='35' align='left'><span id='p_end'>"
    				+ ((total > size) ? (page*size) : total)
    				+ "</span></td><td width='85' align='left'>条记录 / 共</td><td width='40' align='left'><span id='p_count'>"
    				+ total
    				+ "</span></td><td width='50' align='center'>条记录</td></tr></table>");
    		s.append("<span id='p_data_empty' class='p_bar p_label' "+(total>0?"style='display:none;'":"")+">当前没有可以显示的数据</span>");
    		s.append("</td></tr></table>");
    		s.append("<input type='hidden' id='P_N' name='P_N' value='"+page+"' />");
    		s.append("<input type='hidden' id='P_W' name='P_W' />");
    		s.append("<input type='hidden' id='P_ALL' name='P_ALL' value='"+maxPage+"' />");
    		s.append("<input type='hidden' id='D_ALL' name='D_ALL' value='"+total+"' />");
    		s.append("<input type='hidden' id='P_SIZE' name='P_SIZE' value='"+size+"' />");
    		s.append("<script type='text/javascript' src='../cseipm/js/pagenation.js'></script>");
    		return s.toString();
    	}
    	
    	/**
    	 * 获取分页信息
    	 * @param total
    	 * @param size
    	 * @param page
    	 * @param type
    	 * @return
    	 */
    	public static int[] getPage(int total, int size, int page, String type){
    		int[] s = new int[4];
    		int quotient = total / size;
    		int remainder = total % size;
    		if(remainder>0){
    			quotient += 1;
    		}
    		if(type.equals("first")){
    			page = 1;
    		}else if(type.equals("previous")){
    			page -= 1;
    		}else if(type.equals("next")){
    			page += 1;
    		}else if(type.equals("last")){
    			page = quotient;
    		}
    		s[0] = page;
    		s[1] = quotient;
    		s[2] = (page-1)*size+1;
    		s[3] = page*size;
    		return s;
    	}
    }
    

      

  • 相关阅读:
    jQuery UI DatePicker用法和中文设置
    jQuery的ajax方法
    jQuery遍历复杂的JSON数据
    JavaScript面向对象的写法
    jpa
    日志
    全局异常的处理!
    oracle表空间
    plsql的连接配置
    pLsql使用
  • 原文地址:https://www.cnblogs.com/demon09/p/9082129.html
Copyright © 2020-2023  润新知