Ajax分页插件Pagination从前台jQuery到后端java总结(2)

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

Dao层: (可以跳过)

public List selectIndexById(int indexId){ List<Content>list=new ArrayList<Content>(); try{ conn = DBConn.getCon(); String sql = "select * from T_Content,T_User where T_Content.AuthorId = T_User.UserId and CatlogId=? order by CreateDate desc"; pstm = conn.prepareStatement(sql); pstm.setInt(1, indexId); rs = pstm.executeQuery(); SimpleDateFormat ff=new SimpleDateFormat("yyyy年MM月dd日 hh时mm分"); while(rs.next()){ Content content = new Content(); content.setContentId(rs.getInt("ContentId")); content.setCaption(rs.getString("Caption")); content.setCreateDate(f.format(rs.getTimestamp("CreateDate"))); content.setTimes(rs.getInt("Times")); content.setSource(rs.getString("Source")); content.setText(rs.getString("Text")); content.setPic(rs.getString("Pic")); content.setRefPic(rs.getString("RefPic")); content.setHot(rs.getInt("Hot")); User user = new User(); user.setUserId(rs.getInt("UserId")); content.setAuthorId(user); Catlog catlog = new Catlog(); //CntURL待开发 catlog.setCatlogId(rs.getInt("CatlogId")); content.setCatlog(catlog); list.add(content); } }catch(Exception e){ e.printStackTrace(); }finally{ DBConn.closeDB(conn, pstm, rs); } return list; }

精彩专题分享:jquery分页功能操作  JavaScript分页功能操作

以上就是网页所实现的分页代码,easy-ui部分的分页也可以参考以上代码。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzsyjf.html