手動分頁(簡單易懂)

2021-08-21 10:10:00 字數 2466 閱讀 4497

寫了乙個簡單的分頁查詢,希望對你們有幫助:

就不多說了,直接看操作:

首先是我們的dao層

這裡為什麼加@param呢,因為我們穿的是多個引數,但是系統不知道你傳的是多個引數,就需要用@param來宣告一下這個變數

//分頁+查詢

listfindbypage(@param("hy")hy hy,@param("pageno")integer pageno,@param("pagesize")integer pagesize,@param("mingcheng")string mingcheng);

//條數

long findcount(@param("hy")hy hy,@param("mingcheng")string mingcheng);

這個地方因為構造表的時候沒用使用連表,所以在這個地方加了乙個連線查詢,最後給他了乙個分頁排序

要注意!!一定是排序在前邊,分頁在後邊。。想當年。。因為這個栽了乙個大坑。。咳咳。。忽略這點水文

select * from hy inner join gongsi on hy.gongsi_id=gongsi.id

and hy.id=#

and nicheng like concat('%',#,'%')

and xingbie=#

and leibie=#

and shenfen=#

and shiqv=#

and xingming=#

and shoujihao=#

and tuijianrenid=#

and gongsi.mingcheng like concat('%',#,'%')

order by hy.id desc limit #,#

select count(2) from hy inner join gongsi on hy.gongsi_id=gongsi.id

and hy.id=#

and nicheng like concat('%',#,'%')

and xingbie=#

and leibie=#

and shenfen=#

and shiqv=#

and xingming=#

and shoujihao=#

and tuijianrenid=#

and gongsi.mingcheng like concat('%',#,'%')

下面是我們的serivce層:

//因為在dao加了@param,所以這個地方就不用加了

listfindbypage(hy hy, integer pageno, integer pagesize,string mingcheng);

long findcount(hy hy,string mingcheng);

然後是serivce的實現類:

@override 

public listfindbypage(hy hy, integer pageno, integer pagesize,string mingcheng)

if(pageno == null)

if(pagesize == null)

return hydao.findbypage(hy, (pageno-1)*pagesize, pagesize,mingcheng);

}@override

public long findcount(hy hy,string mingcheng)

return hydao.findcount(hy,mingcheng);

}

最後是我們的controller層:

// 分頁+提示

// 這個是寫在最上邊的

// 開始為第一頁

private integer pageno = 1;

// 每頁顯示15條

private static integer pagesize = 15;

// 總條數

private long totalcount;

private long totalpage;

// 彈窗

private string prompt;

public string hylist(model model, @requestparam(value = "pageno", defaultvalue = "1") integer pageno, hy

hy,string mingcheng) else if (hy.getleibie() == 1)

} return null;

}

忘了還有乙個jsp頁面。。。

這個地方我就直接給你看分頁的這一部分

gridview手動分頁

protected void page load object sender,eventargs e public void gridviewdatabind gridview1.datasource ds.tables customers gridview1.allowpaging true gr...

手動實現Gridview分頁

後台 using system using system.collections.generic using system.linq using system.web using system.web.ui using system.web.ui.webcontrols using system.d...

javaWeb簡單易懂

武松 瀏覽器。酒館 伺服器。店小二 廚師 servlet或者jsp。來三碗好酒!瀏覽器向伺服器發出http請求。店小二上酒 伺服器的響應。武松從進店到離開 乙個http對話。我們可以看到,web互動的最基本單位為http請求 武松點菜 每個使用者從進入 到離開 這段過程稱為乙個http會話 武松進店...