怎麼實現列表分頁功能,並且給前端返回總條數和總頁數

2021-10-24 12:29:37 字數 3285 閱讀 9591

1、資料庫:mysql     ==>      mysql用的是limit進行分頁查詢

**示例:

語句1:select * from student limit 0,10

語句2:select * from student limit 10 offset 0

2、計算分頁頁數:

首先通過sql查詢出滿足條件的總記錄數(totalcount):

select  count(1) from tablename
之後計算總頁數(totalpage):

double totalpage = math.ceil(totalcount/ 10)        (這裡每頁記錄數使用固定值10,可換為變數)

即:math.ceil(  23.0 /10 )==> 3.0   (拓展:向下取整:math.floor())

totalpage的型別將影響結果:

如果totalpage使用int型別==> 如:  23/10  ==>2    ,如取double型別 ==>如: 23.0/10 = 2.3

下面為具體案例:

工單列表:

select

two.cust_id as custid

from tb_work_order two

join tc_work_type twt on two.work_type = twt.work_type

join tc_work_class twcs on two.work_class = twcs.work_class

and two.status=#

order by two.urgency desc,two.create_date desc limit #,10;

工單列表總條數:(注意是返回是double型別,前面已提到作用)

select count(1) from tb_work_order two

join tc_work_type twt on two.work_type = twt.work_type

join tc_work_class twcs on two.work_class = twcs.work_class

and two.status=#

//工單列表

listselectbycompanycode(@param("companycode") string companycode, @param("status") string status,@param("startindex") integer startindex);

//工單列表count

double selectcount(@param("companycode") string companycode, @param("status") string status);

列表:

@override

public listselectbycompanycode(string status,string companycode,integer page)

列表count:

@override

public double selectcount(string status,string companycode)

//工單列表

double totalpage1 = math.ceil(totalcount1/10);//向上取整

integer totalpage = totalpage1.intvalue();

integer totalcount = totalcount1.intvalue();

//返回字段

webapi.settotalcount(totalcount);//總記錄數

webapi.settotalpage(totalpage);//總頁數

webapi.setreturncode(0);

webapi.setmessage("成功");

return webapi;

}

/**

*/public class webapipage

public webapipage(int totalcount,int totalpage,int returncode, string message, t result)

private int totalcount;

private int totalpage;

private int returncode;

private string message="";

private t result;

public int gettotalcount()

public void settotalcount(int totalcount)

public int gettotalpage()

public void settotalpage(int totalpage)

public int getreturncode()

public void setreturncode(int returncode)

private void init()

public string getmessage()

public void setmessage(string message)

public t getresult()

public void setresult(t result)

/*** 重新設定返回值

*/public void reset(int totalcount,int totalpage,int returncode, string message)

/*** 重新設定返回值

*/public void reset(int totalcount,int totalpage,int returncode, string message, t result)

}

Mybatis實現聯表查詢並且分頁功能

今天同學突然問我這個怎麼搞。然後自己搞了一下發現這個玩意有坑。就記錄一下 person表 cat表 乙個person有多個cat 實體類就這麼寫 person實體類 data public class person implements serializable cat實體類 data public...

前端結合elementui實現分頁功能

在elementui中使用table元件完成頁面的大概框架,並且使用pagination分頁元件 tips 這裡不是重點,不做過多闡述 通過axios把資料全部渲染到頁面上 使用el pagination分頁元件,定義分頁中的基礎資料 每頁顯示多少資料,資料總條數等 定義乙個新的儲存頁面資料的new...

手寫js前端分頁功能實現

1 先上圖看看分頁結果 html 如下 地名位址 公司企業 機構團體 共找到5條結果 js 如下 function search pagenum,pagesize var newfeature var mapgeometry let points ajax success function r 設定...