Paging
True Page
Click on a night to that data, we use range queries
Select * from jobs where ... limit 0,3
Fake page
We check out all the data, into memory
Paging implementation:
We created a pagination tools,
Package Penalty for cn.jiedada.util; Import java.util.List; / ** This is a do into paging, the current page, next page, previous page, total pages, last page, page, each page size, * the current page directly * calculate the total number of pages this.totalPage = this.totalNum% pageSize == 0 this.totalNum / pageSize:? this.totalNum / pageSize + 1; before calculate a this.prePage = this.localPage == 1 1:? this.localPage-1 ; calculated after a this.nextPage = this.localPage == this.totalPage this.totalPage:? this.localPage +. 1; * @author * * @param <T> * / public class PageBeanUtil <T> { Private Integer localPage; //Pages Private Integer TotalPage; // Per page Private Integer = the pageSize. 5 ; // total data amount Private Integer totalnum; // Home Private Integer = firstPage. 1 ; // Previous Private Integer prePage; // next page Private Integer nextPage; // End Private Integer lastPage; // display data Private List <T> List; public PageBeanUtil () { } public PageBeanUtil(Integer localPage,Integer totalNum) { super(); this.localPage = localPage; this.totalNum = totalNum; //算出总页数 this.totalPage = this.totalNum%pageSize==0?this.totalNum/pageSize:this.totalNum/pageSize+1; //算出前一页 this.prePage = this.localPage==1? 1 : this.localPage-1; //算出后一页 this.nextPage = this.localPage==this.totalPage? this.totalPage : this.localPage+1; this.lastPage = this.totalPage; } public Integer getLocalPage() { return localPage; } public void setLocalPage(Integer localPage) { this.localPage = localPage; } public Integer getTotalPage() { return totalPage; } public void setTotalPage(Integer totalPage) { this.totalPage = totalPage; } public Integer getPageSize() { return pageSize; } public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } public Integer getTotalNum() { return totalNum; } public void setTotalNum(Integer totalNum) { this.totalNum = totalNum; } public Integer getFirstPage() { return firstPage; } public void setFirstPage(Integer firstPage) { this.firstPage = firstPage; } public Integer getPrePage() { return prePage; } public void setPrePage(Integer prePage) { this.prePage = prePage; } public Integer getNextPage() { return nextPage; } public void setNextPage(Integer nextPage) { this.nextPage = nextPage; } public Integer getLastPage() { return lastPage; } public void setLastPage(Integer lastPage) { this.lastPage = lastPage; } public List<T> getList() { return list; } public void setList(List<T> list) { this.list = list; } @Override public String toString() { return "PageBeanUtil [localPage=" + localPage + ", totalPage=" + totalPage + ", pageSize=" + pageSize + ", totalNum=" + totalNum + ", firstPage=" + firstPage + ", prePage=" + prePage + ", nextPage=" + nextPage + ", lastPage=" + lastPage + ", list=" + list + "]"; } }
By constructing this method inside, will be able to directly encapsulated into an object, which can be obtained by calculating this, but tolalNum that we need to query the database
In the service layer, we do statement
@Override public PageBeanUtil<Jobs> page(Integer localPage) { //查询中条数 Integer totalNum = dao.findNum(); if(localPage==null){ localPage=1; } //构造方法 PageBeanUtil<Jobs> pageBean = new PageBeanUtil<Jobs>(localPage, totalNum); //查询 List<Jobs> list = dao.selectLimt((localPage-1)*pageBean.getPageSize(),pageBean.getPageSize()); pageBean.setList(list); return pageBean; }
@Override public Integer findNum() { return template.queryForObject("select count(id) from jobs", Integer.class); } @Override public List<Jobs> selectLimt(int index, Integer pageSize) { // TODO Auto-generated method stub return template.query("SELECT * FROM view_jobs_city LIMIT ?,?", new BeanPropertyRowMapper<Jobs>(Jobs.class),index,pageSize); }
This is the dao layer
<div class = "Container Job-Table"> <Table class = "Table Table-hover"> <TR> <TH class = "hidden-SM"> ID </ TH> <TH> job </ TH> < th> Location </ th> <th> number </ th> <th> salary </ th> <th> is enabled </ th> <th> Name </ th> <th> operating </ th> </ TR> <C: forEach items = "$ {} pageBean.list" var = "J"> <tr> <th>#${j.id }</th> <th>${j.title }</th> <th>${j.cname }</th> <th>${j.jobnum }</th> <th>${j.treatment }</th> <th> <c:if test="${j.isenabled }" var="s"> <span class="glyphicon glyphicon-ok" aria-hidden="true"></span> </c:if> <c:if test="${!s }"> <span class="glyphicon glyphicon-remove" cia-hidden="true"></span> </c:if> </th> <th>${j.inputdate }</th> <th> <a href="system/jobs/update?id=${j.id }" class="btn-default tableA"><span class="glyphicon glyphicon-pencil" aria-hidden="true">修改</span></a> <a href="system/jobs/del?id=${j.id }" class="btn-default tableA"><span class="glyphicon glyphicon-trash" aria-hidden="true">删除</span></a> </th> </tr> </c:forEach> </table> <!--分页--> <nav class="navbar-right"> <ul class="pagination" id="paging"> <li> <span>当前第${pageBean.localPage }页</span> </li> <li> <a href="system/jobs/page?localPage=1"> <span aria-hidden="true">首页</span> </a> </li> <li> <a href="system/jobs/page?localPage=${pageBean.prePage }" aria-label="上一页"> <span aria-hidden="true"> Previous </ span> <Li> </a> </li> </li> <li> <a href="system/jobs/page?localPage=${pageBean.nextPage }" aria-label="下一页"> <span aria-hidden="true">下一页</span> </a> </li> <li> <a href="system/jobs/page?localPage=${pageBean.lastPage }" aria-label="尾页"> <span aria-hidden="true">尾页</span> </a> </li> <li> <span> Total Number of pages: page $ {pageBean.totalPage} </ span> <span> Total Data: Total $ {pageBean.totalNum} article </ span> </ UL> </ Li> </ NAV> </ div> </ body>
This is the front page of data feedback