前端做資料分頁,至少需要傳給后端的關鍵資料:
- 當前頁碼:pageNum(需要查第幾頁的資料,必須前端提供)
- 每頁顯示資料條數:limit 或 pageSize(可前端傳,可后端自定義)
前端需要的資料,即后端需要查的資料:(可定義 PageHelper 封裝資料)
-
int count:總記錄數 (直接資料庫查即可) -
int pageCount:總頁數(計算可得到)總頁數 = 總記錄數 % 每頁顯示條數 == 0 ? 總記錄數/每頁顯示條數 : 總記錄數/每頁顯示條數 + 1pageCount = count % limit == 0 ? count/limit : count/limit + 1 -
List<T> list:當前頁資料(分頁查詢得到)
資料庫分頁查詢需要的關鍵資料:
-
int start:起始索引(有計算公式)起始索引 = (當前頁碼 - 1) * 每頁顯示條數start = (pageNum - 1) * limit -
int limit:每頁顯示條數(需要查幾條)
分頁查詢關鍵 SQL:select xxx from table limit 起始索引,每頁顯示條數
都看到最后了,右下角來個贊鴨!-.- 歡迎評論留言~
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/537759.html
標籤:其他
