limit使用
limit? 起始位置?废菱,查詢條數(shù)
m*(n-1)? m(頁數(shù))? n(條數(shù))
查詢語句寫limit
public PageBean findCustomersByPage(int currPage) throws Exception {
//當(dāng)前頁 currPage
//自己指定每頁顯示多少數(shù)量的數(shù)據(jù)
int pageSize = 15;
//數(shù)據(jù)庫查詢出總記錄數(shù)
int count = cd.findCustomersCount();
//轉(zhuǎn)成double類型, 方便調(diào)用Math函數(shù)處理總頁數(shù),僅此而已
double totalCount = count;
//總頁數(shù)
int totalPage = (int) Math.ceil(totalCount / pageSize);
//mysql中 使用limit查詢的參數(shù)第一個為 起始記錄數(shù); 第二個為 每頁的數(shù)量
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; }