动态分页类: Cls_page.java

 package pagination;

 public class Cls_page {
private int nums;// 总条目数
private int current_page;// 当前被选中的页码
private int sub_pages;// 每次显示的页数
private int pageNums;// 总页数
private int[] page_array;// 用来构造分页的数组
private String subPage_link;// 每个分页的链接 /**
*
* Cls_page是的构造函数,用来在创建类的时候自动运行.
*
* @disNums 列表记录显示条数
* @nums 总条目数
* @current_page 当前被选中的页
* @sub_pages 每次显示的页数
* @subPage_link 每个分页的链接
*
* 函数subPageCss(): 当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10
* [下页] [尾页]
*/ public Cls_page(int disNums, int nums, int current_page, int sub_pages,
String subPage_link) {
this.nums = nums;
if (current_page == 0) {
this.current_page = 1;
} else {
this.current_page = current_page;
}
this.sub_pages = sub_pages;
this.page_array = new int[this.sub_pages];
int nums2 = nums;
int disNums2 = disNums;
this.pageNums = (nums2 / disNums2);
this.subPage_link = subPage_link; } /*
* 用来给建立分页的数组初始化的函数。
*/
public int[] initarray() {
for (int i = 0; i < this.sub_pages; i++) {
this.page_array[i] = i;
}
return this.page_array;
} /*
* construct_num_Page该函数使用来构造显示的条目 即使:[1][2][3][4][5][6][7][8][9][10]
*/
public int[] construct_num_page() {
int[] current_array;
if (this.pageNums < this.sub_pages) {
current_array = new int[this.pageNums];
for (int i = 0; i < this.pageNums; i++) {
current_array[i] = i + 1;
}
} else {
current_array = this.initarray(); if (this.current_page <= 3) {
for (int i = 0; i < current_array.length; i++) {
current_array[i] = i + 1;
}
} else if (this.current_page <= this.pageNums
&& this.current_page > this.pageNums - this.sub_pages + 1) {
for (int i = 0; i < current_array.length; i++) {
current_array[i] = (this.pageNums) - (this.sub_pages) + 1
+ i;
} } else {
for (int i = 0; i < current_array.length; i++) {
current_array[i] = this.current_page - 2 + i; }
} } return current_array;
} /*
* 构造分页 当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10 [下页] [尾页]
*/ public String subPageCss() {
String subPageCssStr = "";
subPageCssStr += "当前第" + this.current_page + "/" + this.pageNums + "页 ";
if (this.current_page > 1) {
String firstPageUrl = this.subPage_link + "1";
String prewPageUrl = this.subPage_link + (this.current_page - 1);
subPageCssStr += "[<a href='" + firstPageUrl + "'>首页</a>] ";
subPageCssStr += "[<a href='" + prewPageUrl + "'>上一页</a>] ";
} else {
subPageCssStr += "[首页] ";
subPageCssStr += "[上一页] ";
} int[] a = this.construct_num_page(); for (int i = 0; i < a.length; i++) {
int s = a[i];
if (s == this.current_page) {
subPageCssStr += "[<span style='color:red;font-weight:bold;'>"
+ s + "</span>]";
} else {
String url = this.subPage_link + s;
subPageCssStr += "[<a href='" + url + "'>" + s + "</a>]"; }
} if (this.current_page < this.pageNums) {
String lastPageUrl = this.subPage_link + this.pageNums;
String nextPageUrl = this.subPage_link + (this.current_page + 1);
subPageCssStr += " [<a href='" + nextPageUrl + "'>下一页</a>] ";
subPageCssStr += "[<a href='" + lastPageUrl + "'>尾页</a>] ";
} else {
subPageCssStr += "[下一页] ";
subPageCssStr += "[尾页] ";
}
subPageCssStr += " 共" + this.nums + "条记录"; return subPageCssStr;
} }

 调用页面:index.jsp

 <%@ page language="java" import="java.util.*,pagination.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head> <body> JAVA动态分页类调用<hr/>
<%
String p = request.getParameter("p") == null ? "1" : request.getParameter("p");//获取页码
int pagenum = Integer.parseInt(p);//转为int类型
int limit = 10;//显示条数
int start = (pagenum - 1) * limit;//开始位置
int nums = 400;//总条目数 //输出测试
for (int i = start; i < start + limit; i++) {
out.print(i + 1 + ".................................................<br/>");
} //调用分页类 new Cls_page(列表记录显示条数, 记录总条数, 当前被选中的页码, 页码链接数,每个分页的路径)
Cls_page cls = new Cls_page(limit, nums, pagenum, 10,"index.jsp?p=");
out.print(cls.subPageCss());
%> </body>
</html>

运行结果:

JAVA动态分页类调用


31.................................................
32.................................................
33.................................................
34.................................................
35.................................................
36.................................................
37.................................................
38.................................................
39.................................................
40.................................................
当前第4/40页 [首页] [上一页] [2][3][4][5][6][7][8][9][10][11] [下一页] [尾页] 共400条记录

Java 动态分页类的更多相关文章

  1. DedeCMS织梦动态分页类,datalist标签使用实例

    <?php require_once(dirname(__FILE__)."/include/common.inc.php");//载入基础文件 require_once(D ...

  2. 初看Mybatis 源码 (二) Java动态代理类

    先抛出一个问题,用过Mybatis的都知道,我们只需要定义一个Dao的接口,在里面写上一些CRUD相关操作,然后配置一下sql映射文件,就可以达到调用接口中的方法,然后执行sql语句的效果,为什么呢? ...

  3. Java动态生成类以及动态添加属性

    有个技术实现需求:动态生成类,其中类中的属性来自参数对象中的全部属性以及来自参数对象properties文件. 那么技术实现支持:使用CGLib代理. 具体的实现步骤: 1.配置Maven文件: &l ...

  4. 【原】如何获取Java动态生成类?

    写作目的:Java大部分框架,如Spring,Hibernate等都会利用动态代理在程序运行的时候生成新的类, 有的时候为了学习,或者深入了解动态代理,想查看动态生成类的源代码究竟长怎么个样子, 通过 ...

  5. JAVA“动态”为类添加属性

    部分参考:http://www.cnblogs.com/zy2009/p/6725843.html pom.xml中添加: <dependency> <groupId>comm ...

  6. java动态编译类文件并加载到内存中

    如果你想在动态编译并加载了class后,能够用hibernate的数据访问接口以面向对象的方式来操作该class类,请参考这篇博文-http://www.cnblogs.com/anai/p/4270 ...

  7. php动态分页类

    <?php /** * 页面名称:cls_page.php */ class Page { private $each_disNums; //每页显示的条目数 private $nums; // ...

  8. Java动态调用类中方法

    在Java中,调用类的方法有两种方式:对于静态方法可以直接使用类名调用,对于非静态方法必须使用类的对象调用.反射机制提供了比较另类的调用方式,可以根据需要指定要调用的方法,而不必在编程时确定.调用的方 ...

  9. java 动态生成类再编译最后代理

    package spring.vhostall.com.proxy; public interface Store { public void sell(); } ------------------ ...

随机推荐

  1. Java之final的解析

    在Java中,final关键字可以用来修饰类.方法和变量(包括成员变量和局部变量). 当用final修饰一个类时,表明这个类不能被继承. 对于一个final变量,如果是基本数据类型的变量,则其数值一旦 ...

  2. php文件缓存

    1.最新代码 <?php class cache { private static $_instance = null; protected $_options = array( 'cache_ ...

  3. Introduction to object

    1 Declarations VS definitions     (Page 81)     declarations: This function or variable exists somew ...

  4. 基于python做的抓图程序1.0.00版本

    #coding=gbkimport urllibimport urllib2import reimport osimport time# import readline def getHtml(url ...

  5. 解决VS2015无法调试dotnet core项目

    dotnet core 1.0正式版和VS2015 update3安装后一直无法在VS中正常调试. 错误提示:The debugger's worker process (msvsmon.exe) u ...

  6. linux下删除内核

    一.概述 笔者的Ubuntu系统刚安装成功后,就不知道怎么会有多个内核,但实际上默认运行的只有一个.在grub启动界面多余的启动项和多余内核占用的存储空间迫使我产生了铲除多余内核的冲动. 最近,自己从 ...

  7. 【关于php】Appserv的安装注意事项

    之前的安装,问题应该不大,一路点“安装——Next——next·····”就行,下面是一些注意事项: (1)AppServ安装路径的选择.具体安装在哪个磁盘下用户可以自行选择,也可以使用默认的安装位置 ...

  8. 优先级和lisp式前缀表达式

    if(f(a,b) > 0) # 1 if(f(a, b>0)) # 2 上面在调用f的时候,1使用括号表明了参数的优先级,不然会出现2这样的情况. 而使用lisp式的前缀表达式则不会有不 ...

  9. Origin null is not allowed by Access-Control-Allow-Origin

    http://www.cnblogs.com/accessking/archive/2012/05/12/2497000.html http://bbs.csdn.net/topics/3903099 ...

  10. Hidden Password

    zoj1729:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=729 题意:就是求字符串的最小表示,模板题. 题解:直接贴模板. ...