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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何进行模糊分页

發布時間:2024/7/23 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何进行模糊分页 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用模糊分頁需要3個參數:關鍵字:key,當前頁:page,查詢內容個數:count

核心代碼:

//所有菜單列表+分頁private void foodList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String page = request.getParameter("page");//模糊查詢 關鍵字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);//查找所有菜品并分頁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頁面:

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

附件:pageUtils代碼:

package com.baidu.utils;public class PageUtils {private String page; //當前頁private int pageSize; //每頁顯示數目private int count; //總數據個數public PageUtils(String page, int pageSize, int count) {super();this.page = page;this.pageSize = pageSize;this.count = count;//初始化當前頁initCurrPage();//初始化最后一頁initLastPage() ;//初始化下一頁initNextPage() ;//初始化上一頁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;}}

?

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。