<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                核心代碼 web ~~~ //分頁查詢 public void queryCategoryList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 1 調用service中的查詢方法 try { String tmp=request.getParameter("currentPage"); String tmp1=request.getParameter("currentCount"); int currentPage = Integer.parseInt(tmp);//當前頁 int currentCount = Integer.parseInt(tmp1);//當前總數 //沒參數設置為第一頁 // 給分頁數據設置默認值 if (currentCount==0){ currentCount=5; } if (currentPage==0){ currentPage=1; } CategoryService service=new CategoryService(); Page page = service.findPageCategory(currentPage, currentCount); if (page!=null) { request.setAttribute("page",page); request.getRequestDispatcher("/category-list.jsp").forward(request,response); } else { request.getRequestDispatcher("/category-list.jsp").forward(request,response); } } catch (SQLException e) { e.printStackTrace(); } } ~~~ service ~~~ //分頁查詢 public Page findPageCategory(int currentPage, int currentCount) throws SQLException { Page page=new Page(); // 1 查詢出生鮮數據的總數 CategoryDao dao = new CategoryDao(); int totalCount = dao.queryCount(); /* 總數 每頁顯示數目 總頁數 9 10 0.9 1 10 10 1 1 11 10 1.1 2 java ceil */ // 2 根據總數和當前頁顯示數 計算出總頁數 int totalPage= (int) Math.ceil(1.0*totalCount/currentCount); //3 將分頁相關信息封裝到page類中 page.setCurrentCount(currentCount); page.setCurrentPage(currentPage); page.setTotalCount(totalCount); page.setTotalPage(totalPage); // 計算查詢的起始位置 // 頁數 每頁顯示條數 起始位置 // // 1 3 0 // 2 3 3 // 3 3 6 (currentPage-1)*currentCount //計算出起始位置 int startPosition=(currentPage-1)*currentCount; // 分頁查詢數據 List<Category> categories = dao.queryPageCategoryList(startPosition,currentCount); // 將集合數據封裝到page類中 page.setList(categories); return page; } ~~~ dao ~~~ //分頁查詢 public List<Category> queryPageCategoryList(int startPosition, int currentCount) throws SQLException { ComboPooledDataSource dataSource=new ComboPooledDataSource(); QueryRunner queryRunner=new QueryRunner(dataSource); String sql="select * from category limit ?,?"; List<Category> categoryList = queryRunner.query(sql, new BeanListHandler<Category>(Category.class),startPosition,currentCount); return categoryList; } ~~~ 前端 ~~~ <!--分頁 --> <nav> <ul class="pagination pull-right"> <li class="previous"><a href="#">&laquo;</a></li> <c:forEach begin="1" end="${page.totalPage}" var="Page"> <li><a href="${pageContext.request.contextPath}/category?method=queryCategoryList&currentPage=${Page}&currentCount=5">${Page}</a></li> </c:forEach> <li><a href="#">&raquo;</a></li> </ul> </nav> ~~~ 結果 ![](https://box.kancloud.cn/ef77b59ee9769793598a25e60f87a1d8_1585x814.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看