• 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";
        }
    
    
  • 相关阅读:
    android 异步加载图片缩略图
    Java小工具===》在目录内查找包含××(字符串)的文件,并显示行号
    android 录像和拍照功能
    基于socket的上传下载(Java)精简版
    android 瀑布流简单例子
    创建上下文菜单及监听
    一个简单的win32截图例子
    把位图保存为文件源代码
    进程间通讯 —— 共享内存
    解决WIN32窗口不响应WM_LBUTTONDBLCLK消息
  • 原文地址:https://www.cnblogs.com/famine/p/12323973.html
Copyright © 2020-2023  润新知