日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

如何进行模糊分页

發(fā)布時(shí)間:2024/7/23 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何进行模糊分页 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

使用模糊分頁(yè)需要3個(gè)參數(shù):關(guān)鍵字:key,當(dāng)前頁(yè):page,查詢(xún)內(nèi)容個(gè)數(shù):count

核心代碼:

//所有菜單列表+分頁(yè)private void foodList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String page = request.getParameter("page");//模糊查詢(xún) 關(guān)鍵字String key = request.getParameter("foodName");if(null==page) {page="";}if(null==key) {key="";}Integer count = menuService.count(key);PageUtils pageUtils = new PageUtils(page,6,count);//查找所有菜品并分頁(yè)List<food> list = menuService.foodList(key,(pageUtils.getCurrPage()-1)*6,6);request.setAttribute("pageUtils", pageUtils);request.setAttribute("list", list);request.setAttribute("key", key);request.getRequestDispatcher("/front/detail/caidan.jsp").forward(request, response);}

Html頁(yè)面:

<a href="<%=basePath%>/menu?method=foodList&page=1&foodName=${key}">首頁(yè)</a> <a href="<%=basePath%>/menu?method=foodList&page=${pageUtils.prevPage}&foodName=${key}">上一頁(yè)</a> <a href="<%=basePath%>/menu?method=foodList&page=${pageUtils.nextPage}&foodName=${key}">下一頁(yè)</a> <a href="<%=basePath%>/menu?method=foodList&page=${pageUtils. lastPage}&foodName=${key}">尾頁(yè)</a>

附件:pageUtils代碼:

package com.baidu.utils;public class PageUtils {private String page; //當(dāng)前頁(yè)private int pageSize; //每頁(yè)顯示數(shù)目private int count; //總數(shù)據(jù)個(gè)數(shù)public PageUtils(String page, int pageSize, int count) {super();this.page = page;this.pageSize = pageSize;this.count = count;//初始化當(dāng)前頁(yè)initCurrPage();//初始化最后一頁(yè)initLastPage() ;//初始化下一頁(yè)initNextPage() ;//初始化上一頁(yè)initPrevPage();}private int currPage;private int nextPage;private int lastPage;private int prevPage;public int getNextPage() {return nextPage;}public int getLastPage() {return lastPage;}public int getPrevPage() {return prevPage;}public int getPageSize() {return pageSize;}public int getCurrPage() {return currPage;}private void initCurrPage() {if(null ==page|| "".equals(page)) {page="1";}currPage=Integer.parseInt(page);}private void initLastPage() {lastPage=count/pageSize;if(count%pageSize !=0) {lastPage++;}}private void initNextPage() {nextPage=currPage==lastPage?lastPage:currPage+1;}private void initPrevPage() {prevPage=currPage==1?currPage:currPage-1;}}

?

總結(jié)

以上是生活随笔為你收集整理的如何进行模糊分页的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。