jsp页面 jstl分页显示行号代码测试,

以前记得写了个,写的很长,不好理解,现在遇到了,随手写了个,就才几行代码而已!先留着

package test;

public class JstlPage {

	public static void main(String[] args) {
		int showNum = 10;
		int startR = 1;// 起始
		// 当前页
		int pags = 99; // 总页数
		
		// i==当前页
		for (int i = 0; i < pags; i++) {
			if (i % showNum == 0) {
				System.out.println("起始页" + i + ":翻页");
				System.out.println("\t显示的页码:");
				for (int j = i + 1; j < (i + 1 + showNum); j++) {
					System.out.print(" " + j);
				}
				System.out.println();
			}
		}
	}

}

/** output:
 * 起始页0:翻页
	显示的页码:
 1 2 3 4 5 6 7 8 9 10
起始页10:翻页
	显示的页码:
 11 12 13 14 15 16 17 18 19 20
起始页20:翻页
	显示的页码:
 21 22 23 24 25 26 27 28 29 30
起始页30:翻页
	显示的页码:
 31 32 33 34 35 36 37 38 39 40
起始页40:翻页
	显示的页码:
 41 42 43 44 45 46 47 48 49 50
起始页50:翻页
	显示的页码:
 51 52 53 54 55 56 57 58 59 60
起始页60:翻页
	显示的页码:
 61 62 63 64 65 66 67 68 69 70
起始页70:翻页
	显示的页码:
 71 72 73 74 75 76 77 78 79 80
起始页80:翻页
	显示的页码:
 81 82 83 84 85 86 87 88 89 90
起始页90:翻页
	显示的页码:
 91 92 93 94 95 96 97 98 99 100

 */


以前公司通用的js 异步分页代码,有点长

function createPager(ajaxMethod, id, pageSize)
{
	if (pageSize == undefined)
	{
		pageSize = 20;
	}
	var html = '<div class="xyt-pager" id="pager_'
			+ ajaxMethod
			+ '">    			<div class="xyt-pager-content">	<span id="'
			+ ajaxMethod
			+ '_first" class="disabled" onclick="ajaxPagerNav(\''
			+ ajaxMethod
			+ '\',\'F\')">首页</span>        			<span id="'
			+ ajaxMethod
			+ '_prev" class="xyt-pager-left disabled opacity" title="上一页" onclick="ajaxPagerNav(\''
			+ ajaxMethod
			+ '\',\'P\')"></span>        			<span class="default">第 <input type="text" size="5" maxLength="10" id="'
			+ ajaxMethod
			+ '_currentPage" value="0" onkeypress="event.returnValue=((event.keyCode >= 48) && (event.keyCode <= 57));if(event.keyCode==13){if(!isPos(this.value)){this.value=1;}else{ajaxPagerNav(\''
			+ ajaxMethod
			+ '\',\'C\');}}"/> / <span id="'
			+ ajaxMethod
			+ '_totalPage">0</span> 页</span>        			<span class="default">        				每页 <span id="'
			+ ajaxMethod
			+ '_pageSize">0</span> 条记录        				共 <span id="'
			+ ajaxMethod
			+ '_dataSize">0</span> 条记录        			</span>        			<span id="'
			+ ajaxMethod
			+ '_next" class="xyt-pager-right disabled opacity" title="下一页" onclick="ajaxPagerNav(\''
			+ ajaxMethod
			+ '\',\'N\')"></span>        			<span id="'
			+ ajaxMethod
			+ '_last" class="disabled" onclick="ajaxPagerNav(\''
			+ ajaxMethod
			+ '\',\'L\')">末页</span>        		</div>        		<input type="hidden" name="pageSize" value="'
			+ pageSize
			+ '"/>        		<input type="hidden" name="currentPage" value="1"/>        	 </div>';
	if (id == undefined)
	{
		document.writeln(html);
	} else
	{
		$("#" + id).html(html);
	}
}

function ajaxPagerNav(ajaxMethod, nav)
{
	//10进制
	var dataSize = parseInt($("#" + ajaxMethod + "_dataSize").html(), 10);
	var pageSize = parseInt($("#pager_" + ajaxMethod + ">[name='pageSize']")
			.val(), 10);
	var currentPage = parseInt($("#" + ajaxMethod + "_currentPage").val(), 10);
	var totalPage = 0;
	if (dataSize < pageSize)
	{
		totalPage = 1;
	} else
	{
		totalPage = dataSize / pageSize;
		totalPage += dataSize % pageSize > 0 ? 1 : 0;
	}
	totalPage = parseInt(totalPage + "", 10);
	if (nav == "P")
	{
		if (currentPage <= 1)
		{
			return;
		}
		currentPage -= 1;
	} else if (nav == "F")
	{
		if (currentPage <= 1)
		{
			return;
		}
		currentPage = 1;
	} else if (nav == "N")
	{
		if (currentPage >= totalPage)
		{
			return;
		}
		currentPage += 1;
	} else if (nav == "L")
	{
		if (currentPage >= totalPage)
		{
			return;
		}
		currentPage = totalPage;
	} else if (nav == "C")
	{
		if (currentPage > totalPage || currentPage < 1)
		{
			return;
		}
	}
	$("#pager_" + ajaxMethod + ">[name='currentPage']").val(currentPage);
	eval(ajaxMethod + "()");
}

function setAjaxPagerValues(ajaxMethod, dataSize, pageSize, currentPage)
{
	var totalPage = 0;
	if (dataSize < pageSize)
	{
		totalPage = 1;
	} else
	{
		totalPage = dataSize / pageSize;
		totalPage += dataSize % pageSize > 0 ? 1 : 0;
	}
	totalPage = parseInt(totalPage + "", 10);
	if (dataSize == 0)
	{
		currentPage = 1;
	}
	if (currentPage > totalPage)
	{
		currentPage = 1;
	}
	$("#" + ajaxMethod + "_currentPage").val(currentPage);
	$("#" + ajaxMethod + "_totalPage").html(totalPage);
	$("#" + ajaxMethod + "_dataSize").html(dataSize);
	$("#" + ajaxMethod + "_pageSize").html(pageSize);
	$("#pager_" + ajaxMethod + ">[name='pageSize']").val(pageSize);
	$("#pager_" + ajaxMethod + ">[name='currentPage']").val(currentPage);
	$("#" + ajaxMethod + "_first").attr("class",
			currentPage > 1 ? "" : "disabled");
	$("#" + ajaxMethod + "_last").attr("class",
			currentPage == totalPage ? "disabled" : "");
	$("#" + ajaxMethod + "_prev").attr(
			"class",
			currentPage > 1 ? "xyt-pager-left"
					: "xyt-pager-left disabled opacity");
	$("#" + ajaxMethod + "_next").attr(
			"class",
			currentPage == totalPage ? "xyt-pager-right disabled opacity"
					: "xyt-pager-right");
}

java 分页代码 改日奉上

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。