數據分頁時每頁首條記錄索引如何計算
現在有8條數據,數據庫中第一條索引是0,也就是每條數據的索引分別是0,1,2,3,4,5,6,7 。
現在要求每頁是2條也就是pagesize = 2,當前頁為currentPage。
模擬分頁:0 1 | 2 3 | 4 5 | 6 7
第1頁currentPage = 1,pagesize = 2,首條記錄索引為0,(1 - 1) * 2
第2頁currentPage = 2,pagesize = 2,首條記錄索引為2,(2 - 1) * 2
第3頁currentPage = 3,pagesize = 2,首條記錄索引為4,(3 - 1) * 2
第4頁currentPage = 4,pagesize = 2,首條記錄索引為6,(4 - 1) * 2
可以得到start = (currentPage - 1) * pageSize
最後更新:2017-04-04 07:32:09