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;

}

});

效果图

这里写图片描述
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小虎哥的技术博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值