limit使用
limit 起始位置 ,查询条数
m*(n-1) m(页数) n(条数)
查询语句写limit
public PageBean findCustomersByPage(int currPage) throws Exception {
//当前页 currPage
//自己指定每页显示多少数量的数据
int pageSize = 15;
//数据库查询出总记录数
int count = cd.findCustomersCount();
//转成double类型, 方便调用Math函数处理总页数,仅此而已
double totalCount = count;
//总页数
int totalPage = (int) Math.ceil(totalCount / pageSize);
//mysql中 使用limit查询的参数第一个为 起始记录数; 第二个为 每页的数量
int begin = (currPage - 1) * pageSize;List list = cd.findCustomerByPage(begin , pageSize);
//封装
PageBean pg = new PageBean(); pg.setCurrPage(currPage);
pg.setPageSize(pageSize);
pg.setCount(count); pg.setTotalPage(totalPage); pg.setList(list); return pg; }