web--7.分页显示

来源:互联网 发布:淘宝卖家怎么联系快递 编辑:程序博客网 时间:2024/06/05 05:36

1      PageBean

/** * 分页显示数据类 */public classPageBean<T> {   private Integer page;// 当前页数.   private Integer limit;// 每页显示记录数   private Integer totalCount;// 总记录数   private Integer totalPage;// 总页数.   private List<T> list; // 显示到浏览器的数据.   public Integer getPage() {      return page;   }   public void setPage(Integer page) {      this.page = page;   }   public Integer getLimit() {      return limit;   }   public void setLimit(Integer limit) {      this.limit = limit;   }   public Integer getTotalCount(){      return totalCount;   }   public void setTotalCount(Integer totalCount) {      this.totalCount = totalCount;   }   public Integer getTotalPage(){      return totalPage;   }   public void setTotalPage(Integer totalPage) {      this.totalPage = totalPage;   }   public List<T> getList(){      return list;   }   public void setList(List<T> list) {      this.list = list;   }  }

 

2      分页service

 

//分类页面显示商品的方法public PageBean<Product> findByPage(Integer cid, Integer page) {PageBean<Product> pageBean =  new PageBean<>();//1. 当前页数.pageBean.setPage(page);//2. 每页显示记录数int limit = 12; pageBean.setLimit(limit);//3. 总记录数Integer totalCount = productDao.findCountByCid(cid);pageBean.setTotalCount(totalCount);//4.总页数int totalPage = 0; if(totalCount % limit == 0){totalPage = totalCount / limit;}else{totalPage = totalCount / limit + 1;}pageBean.setTotalPage(totalPage);//5. 显示到浏览器的数据.int begin = (page - 1) * limit;List<Product> list = productDao.findByPage(cid,begin ,limit);pageBean.setList(list);return pageBean;}


 

3      Jsp