分頁 商品列表 商品搜尋

2021-09-24 16:48:15 字數 3176 閱讀 9246

分頁:

select * from product limit 3, 2;從第三條往後取兩條資料(不包括第三條,從1開始數起)

string sql = "select * from product limit " + (pageno-1)*pagesize + "," + pagesize;

計算總共有多少頁的演算法:

總記錄數:totalrecords=select count(*) from tablename;

總頁數第一種演算法:

if(totalreocrds%pagesize!=0)

tatalpages=totalrecords/pagesize+1;

else

totalpages=totalrecords/pagesize;

總頁數第二種演算法:

totalpages=(totalrecords+pagesize-1)/pagesize;

productmysqldao中的函式:

//得到總共多少頁,其中pagesize為函式引數

public int getpagecount(int pagesize) catch (sqlexception e1) finally

return pagecount;

} //得到每頁的產品,其中pageno與pagesize為引數

public listgetproducts(int pageno, int pagesize)

} catch (sqlexception e) finally

return products;

}商品列表jsp的設計:

<%!

final static int page_size = 3;

%>

<%

string strpageno = request.getparameter("pageno");

int pageno = 1;

int pagecount = 0;

if(strpageno != null)

if(pageno < 1)

%>

<%

listproducts = new arraylist();

pagecount = productmgr.getinstance().getpagecount(page_size);

if(pageno > pagecount)

products = productmgr.getinstance().getproducts(pageno, page_size);

%>

body中的設計

產品id

........

<%

for(iteratorit = products.iterator(); it.hasnext();)

%>

第<%=pageno %>頁

共<%=pagecount %>頁

第一頁">最後一頁

商品搜尋jsp的設計:

<%!

final static int page_size = 3;

%>

<%

listcategorys = category.getcategorys();

listproducts = new arraylist();

%>

<%

string action = request.getparameter("action");

if(action != null && action.equals("complex"))

else

........

int pageno = 1;

if(request.getparameter("pageno") != null && !request.getparameter("pageno").equals(""))

products = productmgr.getinstance().searchproducts(listid, keyword,........);

%>

搜尋結果

產品id

.........

<%

for(iteratorit = products.iterator(); it.hasnext();)

%>

<%

}%>

當計算搜尋到的記錄共有多少頁時,

將products = productmgr.getinstance().searchproducts(listid, keyword,........);改為

int pagecount = 0;

pagecount = productmgr.getinstance().searchproducts(products, listid, keyword,........);

其中products作為傳遞引數,此函式的設計如下:

public int searchproducts(listproducts, int categoryid, string keyword,........)

if(lowmemberprice > 0 && highmemberprice >0 &&lowmemberprice != highmemberprice && lowmemberprice < highmemberprice)

if(startpdate != null && endpdate != null && startpdate.compareto(endpdate)>0)

string sqlcount = sql.replacefirst("select \\*", "select count(*)");

system.out.println("sqlcount----" + sqlcount);

sql += " limit " + (pageno-1)*pagesize + " ," + pagesize;

system.out.println(sql);

rscount = db.executequery(conn, sqlcount);

try catch (sqlexception e1)

rs = db.executequery(conn, sql);

try

} catch (sqlexception e) finally

return pagecount;}

分頁展示商品

分頁展示商品 需求 將商品進行分頁展示 技術分析 分頁 分頁 將資料按照頁碼劃分,提高使用者的體驗度.分類 物理分頁 開發中經常使用 一次只去資料庫中查詢當前頁需要的資料.邏輯分頁 一次性將所有資料查詢出來,放入記憶體 集合 每次查詢只需要去記憶體中擷取 mysql中分頁 limit 格式1 sel...

商品表分頁 explain

1.以下最基本分頁sql,並分析分頁指標 第一頁 explain select from prod main order by prod id desc limit 0,20 第二頁 explain select from prod main order by prod id desc limit ...

python分頁展示商品

分頁 1 html 注意先導入jquery 在匯入分頁包2 實現輸入框填入數字進行跳轉該頁面 跳轉 3 4 建立檔案utils 建立乙個py檔案 每頁顯示的數目 precatecount 1 5 分頁py from django.core.paginator import paginator fro...