Springmvc table搜索在本頁顯示加分頁

Springmvc table搜索在本頁顯示加分頁

控制器

@RequestMapping(value = "/searchGoodsBylimit/{index}")
    public String searchGoodsBylimitPst(Model model,
            @ModelAttribute Goods goods, @PathVariable String index,
            HttpServletRequest request) {
        System.out.println("商品類型" + goods.getGoodsType() + index);

        if (index == null || index.equals("")) {
            index = "0";
        }

        List<Goods> goodsS = goodsService.selectGoods(goods,
                Integer.parseInt(index), PageParam.limit);

        if (goodsS != null) {
            model.addAttribute("goodsS", goodsS);
        } else {
            model.addAttribute("resultMsg", "沒有該商品");

        }
        int count = goodsService.selectAllCount(goods);
        model.addAttribute("index", index);
        model.addAttribute("count", count);
        model.addAttribute("limit", PageParam.limit);

        System.out.println("第" + index + "數據開始顯示" + goodsS.size() + "條記錄");
        return "goodsManager/showGoods";
    }

網頁

<body>

    <form:form  id="goodsForm" class="goodsForm" modelAttribute="goods" action="" method="get">
    <div style="margin-left:auto;margin-right:auto;width:70%;font-size:13px">
              商品類型<form:input type="text" path="goodsType"  /> 
        商品名稱<form:input type="text" path="goodsName"  /> 
        商品編號<form:input type="text" path="goodsId"  /> 
         <input type="submit"  id="search" value="搜索"/>
         <input type="submit"  id="allgoods" value="全部"/>

    </div>

        <table width="1052" border=0 align=center cellpadding=2 cellspacing=1
            bordercolor="#799AE1" class=tableBorder>
            <tbody>
                <tr>
                    <th align=center colspan=16 style="height: 23px">商品顯示</th>
                </tr>

                <tr align="center" bgcolor="#799AE1" style="height:28px">
                    <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品編號</td>
                    <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品大類</td>
                    <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品名稱</td>
                    <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品規格</td>
                    <td width="10%" align="center" class=txlHeaderBackgroundAlternate>加權進價</td>
                    <td width="10%" align="center" class=txlHeaderBackgroundAlternate>當前售價</td>
                    <td width="10%" align="center" class=txlHeaderBackgroundAlternate>操作</td>

                </tr>


                <c:forEach items="${goodsS}" var="goods">
                    <tr bgcolor="#DEE5FA">
                        <td align="center" id="goodsId" class="txlrow"><c:out
                                value="${goods.goodsId}"></c:out></td>
                        <td align=center id="goodsType" class=txlrow><c:out
                                value="${goods.goodsType}"></c:out></td>
                        <td align=center id="goodsName" class=txlrow><c:out
                                value="${goods.goodsName}"></c:out></td>
                        <td align=center id="goodsContent" class=txlrow><c:out
                                value="${goods.goodsContent}"></c:out></td>
                        <td align=center id="goodsPrice" class=txlrow><c:out
                                value="${goods.goodsPrice}"></c:out></td>
                        <td align=center id="goodsSell" class=txlrow><c:out
                                value="${goods.goodsSell}"></c:out></td>
                     <td align=center class=txlrow> <input type="button" value="編輯"></td>
                    </tr>
                </c:forEach>

            </tbody>
        </table>
        <div id="Pagination"></div>

    </form:form>


</body>

js

    var limit=<%=request.getAttribute("limit")%>;//每頁顯示多少 條數據
    var count=<%=request.getAttribute("count")%>//共多少條數據
    var index=<%=request.getAttribute("index")%>;//當前記錄數

    $('#search').click(function(){
        var path="<%=ppath%>/goodsManager/searchGoodsBylimit/0";
        $("#goodsForm").attr("action",path );
        $("#goodsForm").submit();
    });
    $('#allgoods').click(function(){
        $('input').val("");
        var path="<%=ppath%>/goodsManager/searchGoodsBylimit/0";
        $("#goodsForm").attr("action",path );
        $("#goodsForm").submit();
    });

$(function(){
    $("#Pagination").pagination(count, {
        items_per_page:limit, // 每頁顯示多少條記錄
        current_page: Math.ceil(index/limit),  //當前頁
        num_display_entries:4, // 分頁顯示的條目數
        next_text:"下一頁",
        prev_text:"上一頁",
        num_edge_entries:2, // 連接分頁主體,顯示的條目數
        callback:handlePaginationClick
    });

    function handlePaginationClick(new_page_index, pagination_container) {
        var path="<%=ppath%>/goodsManager/searchGoodsBylimit/" + new_page_index*limit;
        $("#goodsForm").attr("action",path );
        $("#goodsForm").submit();
        return false;

}

});

效果圖

這裏寫圖片描述
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章