1.创建page对象
public class PageUtils {//当前页默认第一页private Integer page = 1;//默认每页10条private Integer limit = 10;//总数private Integer count;//开始行private Integer startRow;//结束行private Integer endRow;public PageUtils(){this.startRow = (page - 1) * limit;this.endRow = page * limit;}public PageUtils(Integer page, Integer limit){this.page = page;this.limit = limit;this.startRow = (page - 1) * limit;this.endRow = page * limit;}public Integer getPage() {return page;}public void setPage(Integer page) {this.page = page;this.startRow = (page - 1) * limit;this.endRow = page * limit;}public Integer getLimit() {return limit;}public void setLimit(Integer limit) {this.limit = limit;this.startRow = (page - 1) * limit;this.endRow = page * limit;}public Integer getCount() {return count;}public void setCount(Integer count) {this.count = count;}public Integer getStartRow() {return startRow;}public void setStartRow(Integer startRow) {this.startRow = startRow;}public Integer getEndRow() {return endRow;}public void setEndRow(Integer endRow) {this.endRow = endRow;}
}
2.为对象赋值
把前端读取到的参数,放入page对象中,传递到mapper查询
3.mysql查询
page对象传递到mapper进行查询
4.前端代码:
后端page页面没有count总数前端有就可以了,能够计算出具体有多少页,
function search(cont,curr){//初始化页面读取,页数$.post(ctx+"purchase/search",{"projectName":$("#projectName").val(),curr:curr},function (data) {//解析if(data.code===0){count=data.count//数据保存displayHtml(data.data)//分页laypage.render({elem: 'pageNum',count: count,page: true, //总页数limit:12,curr: curr || 1,//点击分页后的触发回调方法jump: function(obj, first){if(!first){//点击跳页触发函数自身,并传递当前页:obj.currsearch(cont,obj.curr);}}});}})}//渲染数据用function displayHtml(data) {//写业务代码,把查询的数据实现页面中}//初始化search(cont,curr);
html代码:分页按钮div
<div id="pageNum" ></div>