Pagination(分页) 从前台到后端总结

一:效果图

下面我先上网页前台和管理端的部分分页效果图,他们用的是一套代码。

                                 

回到顶部(go to top)

二:上代码前的一些知识点

此jQuery插件为Ajax分页插件,一次性加载,故分页切换时无刷新与延迟,如果数据量较大不建议用此方法,因为加载会比较慢。

描述参数值 
maxentries总条目数 必选参数,整数 
items_per_page 每页显示的条目数 可选参数,默认是10 
num_display_entries连续分页主体部分显示的分页条目数 可选参数,默认是10 
current_page 当前选中的页面 可选参数,默认是0,表示第1页 
num_edge_entries两侧显示的首尾分页的条目数可选参数,默认是0 
link_to分页的链接 字符串,可选参数,默认是"#" 
prev_text “前一页”分页按钮上显示的文字字符串参数,可选,默认是"Prev" 
next_text “下一页”分页按钮上显示的文字 字符串参数,可选,默认是"Next" 
ellipse_text 省略的页数用什么文字表示可选字符串参数,默认是"…" 
prev_show_always是否显示“前一页”分页按钮布尔型,可选参数,默认为true,即显示“前一页”按钮 
next_show_always 是否显示“下一页”分页按钮 布尔型,可选参数,默认为true,即显示“下一页”按钮 
callback 回调函数 默认无执行效果 
回到顶部(go to top)

三:前台代码部分

复制代码
 1 var pageSize =6;     //每页显示多少条记录2 var total;           //总共多少记录3  $(function() {4     Init(0); //注意参数,初始页面默认传到后台的参数,第一页是0;    5         $("#Pagination").pagination(total, {   //total不能少        6              callback: PageCallback,            7              prev_text: '上一页',             8              next_text: '下一页',              9              items_per_page: pageSize,              
10              num_display_entries: 4,        //连续分页主体部分显示的分页条目数
11              num_edge_entries: 1,           //两侧显示的首尾分页的条目数 
12          });             
13         function PageCallback(index, jq) {     //前一个表示您当前点击的那个分页的页数索引值,后一个参数表示装载容器。  
14              Init(index);      
15         }
16     });
17  
18  function Init(pageIndex){      //这个参数就是点击的那个分页的页数索引值,第一页为0,上面提到了,下面这部分就是AJAX传值了。
19      $.ajax({
20         type: "post",
21       url:"../getContentPaixuServ?Cat="+str+"&rows="+pageSize+"&page="+pageIndex,
22       async: false,
23       dataType: "json",
24       success: function (data) {
25             $(".neirong").empty();
26 /*             total = data.total; */
27             var array = data.rows;
28             for(var i=0;i<array.length;i++){
29                 var info=array[i];
30                 
31                 if(info.refPic != null){
32                 $(".neirong").append('<dl><h3><a href="'+info.CntURL+'?ContentId='+info.contentId+'" title="'+info.caption+'" >'+info.caption+'</a></h3><dt><a href="sjjm.jsp?ContentId='+info.contentId+'" title="'+info.caption+'" ><img src="<%=basePathPic%>'+info.refPic+'" alt="'+info.caption+' width="150" height="95""></a></dt>  <dd class="shortdd">'+info.text+'</dd><span>发布时间:'+info.createDate+'</span></dl>') 
33                 }else{
34                 $(".neirong").append('<dl ><h3><a href="'+info.CntURL+'?ContentId='+info.contentId+'" title="'+info.caption+'" >'+info.caption+'</a></h3><dd class="shortdd">'+info.text+'</dd><span>发布时间:'+info.createDate+'</span></dl>');
35                 };
36          }       
37       },
38       error: function () {
39           alert("请求超时,请重试!");
40       }
41     });  
42 };
复制代码

 

回到顶部(go to top)

四:后台部分(java)

我用的是MVC 3层模型

servlet部分:(可以跳过)

复制代码
 1     public void doPost(HttpServletRequest request, HttpServletResponse response)2             throws ServletException, IOException {3 4         response.setContentType("text/html;charset=utf-8");5         PrintWriter out = response.getWriter();6         //获取分页参数7         String p=request.getParameter("page"); //当前第几页(点击获取)8         int page=Integer.parseInt(p);9         
10         String row=request.getParameter("rows");    //每页显示多少条记录
11         int    rows=Integer.parseInt(row);
12         
13         String s=request.getParameter("Cat");   //栏目ID
14         int indexId=Integer.parseInt(s);
15         JSONObject object=(new ContentService()).getContentPaiXuById(indexId, page, rows);        
16         out.print(object);
17         out.flush();
18         out.close();
19     }
复制代码

Service部分:(可以跳过)

复制代码
    public JSONObject getContentPaiXuById(int indexId, int page, int rows) {JSONArray array=new JSONArray();List<Content>contentlist1=(new ContentDao()).selectIndexById(indexId);List<Content>contentlist=paginationContent(contentlist1,page,rows);for(Content content:contentlist){JSONObject object=new JSONObject();object.put("contentId", content.getContentId());object.put("caption", content.getCaption());object.put("createDate", content.getCreateDate());object.put("times", String.valueOf(content.getTimes()));object.put("source", content.getSource());object.put("text", content.getText());object.put("pic", content.getPic());object.put("refPic", content.getRefPic());object.put("hot", content.getHot());object.put("userId", content.getAuthorId().getUserId());int id = content.getAuthorId().getUserId();String ShowName = (new UserService()).selectUserById(id).getString("ShowName");object.put("showName", ShowName);array.add(object);}JSONObject obj=new JSONObject();obj.put("total", contentlist1.size());obj.put("rows", array);return obj;}
复制代码

获取出每页的的起止id(这部分是重点),同样写在Service中,比如说假设一页有6条内容,那么第一页的id是从1到6,第二页的id是从7到12,以此类推

复制代码
 1     //获取出每页的内容 从哪个ID开始到哪个ID结束。2     private List<Content> paginationContent(List<Content> list,int page,int rows){3         List<Content>small=new ArrayList<Content>();4         int beginIndex=rows*page;       //rows是每页显示的内容数,page就是我前面强调多次的点击的分页的页数的索引值,第一页为0,这样子下面就好理解了!5         System.out.println(beginIndex);6         int endIndex;7         if(rows*(page+1)>list.size()){   8             endIndex=list.size();        9         }
10         else{
11             endIndex=rows*(page+1);
12         }
13         for(int i=beginIndex;i<endIndex;i++){  
14             small.add(list.get(i));  
15         }  
16         return small;
17     }
复制代码

Dao层:(可以跳过)

复制代码
 1      public List selectIndexById(int indexId){2          List<Content>list=new ArrayList<Content>();3          try{4              conn = DBConn.getCon();5              String sql = "select * from T_Content,T_User where T_Content.AuthorId = T_User.UserId and CatlogId=? order by CreateDate desc";6              pstm = conn.prepareStatement(sql);7              pstm.setInt(1, indexId);8              rs = pstm.executeQuery();9              SimpleDateFormat ff=new SimpleDateFormat("yyyy年MM月dd日 hh时mm分");
10              while(rs.next()){
11                 Content content = new Content();
12                 content.setContentId(rs.getInt("ContentId"));
13                  content.setCaption(rs.getString("Caption"));
14                  content.setCreateDate(f.format(rs.getTimestamp("CreateDate")));
15                  content.setTimes(rs.getInt("Times"));
16                  content.setSource(rs.getString("Source"));
17                  content.setText(rs.getString("Text"));
18                  content.setPic(rs.getString("Pic"));
19                  content.setRefPic(rs.getString("RefPic"));
20                  content.setHot(rs.getInt("Hot"));
21                  User user = new User();
22                  user.setUserId(rs.getInt("UserId"));
23                  content.setAuthorId(user);
24                  Catlog catlog = new Catlog();                //CntURL待开发
25                  catlog.setCatlogId(rs.getInt("CatlogId"));
26                  content.setCatlog(catlog);
27                  list.add(content);
28              }
29          }catch(Exception e){
30              e.printStackTrace();
31          }finally{
32              DBConn.closeDB(conn, pstm, rs);
33          }
34          return list;
35      }
复制代码

 

以上就是网页所实现的分页代码,easy-ui部分的分页也可以参考以上代码。如果有所收获,支持一下哟,谢谢!

转载于:https://www.cnblogs.com/yulei126/p/6790059.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/416812.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

centos7 kafka2.3.1单点部署

依赖环境 kafka依赖zookeeper&#xff0c;故先要进行zookeeper部署&#xff0c;详见centos7 zookeeper部署。 kafka下载 http://kafka.apache.org/downloads http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.3.1/kafka_2.12-2.3.1.tgz 部署 tar xvzf kafka_2.12-2.3.1.t…

zookeeper命令

help帮助命令 ls 查看命令 ls / ls /zookeeper ls /zookeeper/quota /create 创建节点 命令格式&#xff1a;create path data create /whq mytest 创建/whq节点&#xff0c;内容为mytest ///get 查看节点内容 命令格式&#xff1a;get path [zk: localhost:2182(CONNECTED)…

GridControl 选择列、复选框全选(上)

说明&#xff1a; GirdControl 中加入一列&#xff0c;这一列不是写在数据库中的&#xff0c;而是代码中加入的。 图示&#xff1a; 底层类代码&#xff1a; #region GridControl 全选/// <summary>/// 是否选中/// </summary>private static bool chkState false…

msfconsole 无法启动,解决办法

今天突然碰上kali msfconsole 无法启动&#xff0c;经过查找资料&#xff0c;现已成功解决该问题&#xff0c;现将解决办法整理如下&#xff1a; service postgresql start     # 启动数据库服务 msfdb init             # 初始化数据库 msfconsole     …

centos7 zookeeper3.5.6单机伪集群部署

接上篇文章centos7 zookeeper单点部署准备好zookeeper包&#xff0c;进行集群部署 单机伪集群部署 zookeeper1 zookeeper2 zookeeper3 三个目录分别部署一个服务。 cp -r apache-zookeeper-3.5.6-bin/ zookeeper1 cd zookeeper1/ mkdir data vi conf/zoo.cfg 修改 dataDir/op…

centos7 kafka2.3.1单机伪集群部署

接上篇文章centos7 zookeeper单点部署&#xff0c;准备好相应的包 cp config/server.properties config/server0.properties vi config/server0.properties 修改 broker.id0 listenersPLAINTEXT://192.168.81.145:9092 #注意&#xff0c;这里一定要有客户端可访问的ip&…

POJ_2513Colored Sticks 字典树+

比较考察技术含量的一道题。 参考链接:http://blog.csdn.net/lyy289065406/article/details/6647445 题目链接:http://poj.org/problem?id2513 首先差不多能想到这事欧拉路&#xff0c;然后发现没法构图。没有尝试使用map&#xff0c;刚好最近在学字典树就直接上了。 然后就是…

superset0.34源码级别汉化

下载源码 git clone https://github.com/apache/incubator-superset.git cd incubator-superset 切换到0.34版本 git checkout 0.34 进入js打包目录 cd superset/assets/ yarn install yarn build 打包后的文件在superset/assets/dist目录 yarn dev 进行cheap-module-eval-s…

humanize时间库使用及汉化

python3 zh_CN包需要到github下载https://github.com/jmoiron/humanize humanize/locale/zh_CN >>> import humanize >>> import datetime >>> humanize.naturaltime(datetime.timedelta(seconds3)) 3 seconds ago >>> humanize.i18n.ac…

socket编程介绍

Python 提供了两个基本的 socket 模块。 第一个是 Socket&#xff0c;它提供了标准的 BSD Sockets API。 第二个是 SocketServer&#xff0c; 它提供了服务器中心类&#xff0c;可以简化网络服务器的开发。 下面讲的是Socket模块功能 1、Socket 类型 套接字格式&#xff1a; so…

Superset单点登录调整源码

///修改config.py from flask_appbuilder.security.manager import AUTH_REMOTE_USER AUTH_TYPEAUTH_REMOTE_USER from custom_sso_security_manager import CustomSsoSecurityManager CUSTOM_SECURITY_MANAGER CustomSsoSecurityManager AUTH_USER_REGISTRATION True …

webpack-dev-server 搭建本地服务以及浏览器实时刷新

一、概述开发项目中为了保证上线&#xff0c;开发项目是都需要使用localhost进行开发&#xff0c;以前的做法就是本地搭建Apache或者Tomcat服务器。有的前端开发人员 对服务器的搭建和配置并不熟悉&#xff0c;这个时候需要后台开发人员进行帮忙&#xff0c;有的时候后台开发人…

java调用kafka

pom.xml <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId> <version>2.3.1</version> </dependency> 注意调试通过后要添加…

[Noi2015]软件包管理器

来自FallDream的博客&#xff0c;未经允许&#xff0c;请勿转载&#xff0c;谢谢。 Linux用户和OSX用户一定对软件包管理器不会陌生。通过软件包管理器&#xff0c;你可以通过一行命令安装某一个软件包&#xff0c;然后软件包管理器会帮助你从软件源下载软件包&#xff0c;同时…

ELK+Kafka部署

目录 1.背景 2.ELK的配置 2.1.下载 2.2.关闭防火墙 2.3.安装elasticsearch 2.4.安装Logstash 2.5.安装Kibana 2.6.Java日志输出到Logstash 2.7.OSS版本 3.Kafka的配置 3.1.zookeeper搭建 3.2.kafka搭建 4.整合 1.背景 高日志压力情况下&#xff0c;为了避免Logsta…

Allegro改动shape网络节点

使用Allegro时改动shape的网络节点方法&#xff1a; ①选择shape->Select Shape or Void/Cavity ②选择要改动的shape ③点击&#xff08;...&#xff09;改动网络节点的名字 ④改动完毕 转载于:https://www.cnblogs.com/claireyuancy/p/6804046.html