thymeleaf 双重th:each展示订单-商品信息(笔记)

<div class="cart_content"  th:each="oIdList:${orderIdList}">
        <table>
            <tr class="table_head">
                <th>订单号</th>
                <th colspan="3">商品</th>
                <th>商品金额</th>
                <th>商品数量</th>
                <th>总金额</th>
            </tr>
            <tr><td  rowspan="0"><span th:text="${oIdList}"></span></td></tr>
            <tr class="table_content" th:each="o:${orderList}" th:if="${oIdList}==${o.id}" >
                <td class="show_img">
                    <img th:src="${o.image}"  th:value="${o.sid}"
                         th:title="${o.name}"/>
                </td>
                <td class="title" colspan="2"><span th:text="${o.name}">商品名字</span></td>
                <td class="cost">¥<span th:text="${o.price}">20.00</span>元</td>
                <td class="count"><span class="minus">-</span><span class="number" th:text="${o.quantity}">2</span><span class="add">+</span>
                </td>
                <td class="per_sum">¥<span th:with="sum=${o.price}*${o.quantity}" th:text="${sum}">40.00</span>元</td>
            </tr>
            <tr  class="table_content_del_img">
                <td class="delete_img" rowspan="0"><img th:src="@{img/delete_icon.jpg}" th:value="${oIdList}" class="deleteShopCar"/>删除订单</td>
            </tr>
            <tr class="end_pay">
<!--                <td class="is_all"><input id="all" type="checkbox" checked="checked"/>全选</td>-->
<!--                <td class="space" colspan="3"></td>-->
                <td colspan="4" class="all_sum">总价:¥<span>500.00</span>元</td>
                <td colspan="1" class="pay_button_div">
                    <button class="pay_button">结算</button>
                </td>
            </tr>
        </table>
    </div>

Spring MVC的请求方法

 @RequestMapping(value = "getMyOrders.do")
    public String showMyOrders(HttpServletRequest request,
                               Model model){
        Users userInfo = (Users) request.getSession().getAttribute("userInfo");
        model.addAttribute("userInfo",userInfo);
        String uid = userInfo.getSid();

        //存订单id的list
        ArrayList<Integer> orderIdList = new ArrayList<>();
        //存商品列表的list
        List<GoodsCarBean> goodsCarBeans = new ArrayList<>();
        //获取当前账号的订单列表
        //返回model, 通过user id 获取订单号,返回订单中包含的商品信息(名字,价格,图片等等)
        List<OrderForm> orderForms = orderFormService.selectAllByUid(Integer.valueOf(uid));
        for (OrderForm o : orderForms) {
            orderIdList.add(o.getId());
            //订单-商品表 对象   //整个list的订单号都是一样的
            List<GoodsOfOrderForm> goodsOfOrderForms = goodsOfOrderFormService.selectByOFid(o.getId());
            log.info("订单-商品表 对象"+goodsOfOrderForms.toString());
            //for循环去读订单-商品表
            for (GoodsOfOrderForm goodsOfOrderForm:goodsOfOrderForms){
                GoodsCarBean goodsCarBean = new GoodsCarBean();
                goodsCarBean.setUid(o.getUid());
                goodsCarBean.setModified(o.getModified());
                goodsCarBean.setId(o.getId());
                System.out.println("每次当前商品id:"+goodsOfOrderForm.getSid());
                //当前商品数量
                goodsCarBean.setQuantity(goodsOfOrderForm.getQuantity());
                //通过商品id获取商品信息表 对象
                ShopInformation shopInformation = shopInformationService.selectByPrimaryKey(goodsOfOrderForm.getSid());
                log.info("订单-商品表id:" + goodsOfOrderForm.getId() + "商品号:" + shopInformation.getId());
                goodsCarBean.setSid(shopInformation.getId());
                goodsCarBean.setName(shopInformation.getName());
                goodsCarBean.setRemark(shopInformation.getRemark());
                goodsCarBean.setImage(shopInformation.getImage());
                goodsCarBean.setPrice(shopInformation.getPrice().doubleValue());
                goodsCarBean.setSort(getSort(shopInformation.getSort()));
                goodsCarBeans.add(goodsCarBean);
            }
        }
        model.addAttribute("orderList",goodsCarBeans);     //返回订单里的商品里列表 Model
        model.addAttribute("orderIdList",orderIdList);     //返回订单里的商品里列表 Model
        for (GoodsCarBean gcb:goodsCarBeans) {
            System.out.println(gcb.toString());
        }
        return "page/personal/my_orders";
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

人生莫如饥荒

如果对您有帮助,也可以给点赏钱

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

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

打赏作者

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

抵扣说明:

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

余额充值