zoukankan      html  css  js  c++  java
  • 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";
        }
    
    
  • 相关阅读:
    jsp 特殊标签
    poj 1753 Flip Game 高斯消元 异或方程组 求最值
    zoj 3155 Street Lamp 高斯消元 异或方程组 求方案数
    poj1222 EXTENDED LIGHTS OUT 高斯消元解异或方程组 模板
    zoj 3930 Dice Notation 模拟
    zoj 3157 Weapon 线段树求逆序对数
    hdu 1242 Rescue BFS+优先队列
    hdu 3466 Proud Merchants 贪心+01背包
    zoj 3689 Digging 贪心+01背包
    hdu 2602 Bone Collector 01背包模板
  • 原文地址:https://www.cnblogs.com/famine/p/12323973.html
Copyright © 2011-2022 走看看