Pagination(分页) 从前台到后端总结
发表于:2025-02-24 作者:千家信息网编辑
千家信息网最后更新 2025年02月24日,一:效果图下面我先上网页前台和管理端的部分分页效果图,他们用的是一套代码。 回到顶部(go to top)二:上代码前的一些知识点此jQuery插件为Ajax分页插件,一次性加载,故分页切换时无刷新与
千家信息网最后更新 2025年02月24日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'+info.caption+'
'+info.text+' 发布时间:'+info.createDate+'') 33 }else{34 $(".neirong").append('');35 };36 } 37 },38 error: function () {39 alert("请求超时,请重试!");40 }41 }); 42 };
'+info.caption+'
- '+info.text+'
发布时间:'+info.createDate+'
回到顶部(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"); //栏目ID14 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(); Listcontentlist1=(new ContentDao()).selectIndexById(indexId); List 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 ListpaginationContent(List list,int page,int rows){ 3 List small=new ArrayList (); 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 Dao层:(可以跳过)
1 public List selectIndexById(int indexId){ 2 Listlist=new ArrayList (); 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部分的分页也可以参考以上代码。如果有所收获,支持一下哟,谢谢!
参数
部分
按钮
条目
代码
字符
字符串
就是
页数
内容
效果
文字
索引
顶部
前台
主体
后台
布尔
插件
效果图
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
无线模块与远程服务器通信
数据库是依赖程序存在的吗
access数据库合并
网络安全的威肋分为几类
网络安全是学位课吗
天正服务器端口有问题怎么办
松江区工商软件开发哪家好
扬州科技信息互联网公司
黑白网络技术
网络安全答题知识总结
手机电信服务器设置
如何给数据库做一个汇总
华为云数据库访问公网
服务器分机怎么隐藏c盘
服装类软件开发
信息网络安全组织机构表
软件开发的五个步骤
网络安全工资排名
数据库的表和excel表一样吗
红色预警平台软件开发
南宁软件开发的工作室
掌握数据库开发相关技术
软件测试 数据库知识
解决服务器定时自动重启故障
网络安全和信息优势
三个网站怎么合并用户数据库
网络安全和主机应用
科脉收银系统需不需要购云服务器
金山区高科技软件开发推荐厂家
数据库阶段数据管理的主要特点