分頁後獲取當前頁的顯示行數

mysql中分頁可以用limit來實現


例如:

String  sql="select * from shop where EmployeeId ='"+id+"' Limit "+offset+","+count+" ";

count表示一頁顯示多少條;

offset表示偏移量,與count配合使用,用於多次請求,offset = (請求次數 - 1) * count


在實現分頁過後用count(*)來計算查詢到的所有數據量,同上例如:

String sql01="select count(*)from shop where EmployeeId ='"+id+"' ";

後面可以用number來接受這個值(int類型),

if (rs01 != null) {
try {
if(rs01.next()) {
                    number=rs01.getInt(1);
}
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
   }



最後想要知道當前頁所顯示的條目數,定義爲resnumber

int resnumber = items.size();

(items同上一篇文檔裏的作用,是一個接收查詢結果的list)


做完了 覺得蠻簡單,也謝謝潘玉同學的指導!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章