<!-- --------------------------------------- 每行展示一个购物商品---------------------------------------- --> <c:forEach items="${requestScope.cars}" var="car" varStatus="stat"> <input type="hidden" name="id" value="${car.id}"> <tr class="cart_item"> <td class="product-remove"> <!-- <a title="Remove this item" class="remove" href="#">×</a> --> <a href="#" onclick="submit(${car.id })" title="Remove this item" class="remove" >X</a> </td> <%-- <td class="product-thumbnail"> <a href="/collegeimg/${requestScope.g_url[${car.id } ]}"> <img width="145" height="145" alt="poster_1_up" class="shop_thumbnail" src="${pwd}/img/sp/product-thumb-2.jpg"></a> </td> --%> <td class="product-name"> <a href="${pwd }/goods/detial?id=${car.gid}">${car.name}</a> </td> <td class="product-price"> <span class="amount">${car.danjia}</span> </td> <td class="product-quantity"> <div class="quantity buttons_added"> <input type="number" size="4" class="input-text qty text" title="Qty" name = "num" value="${car.num }" min="0" step="1"> </div> </td> <td class="product-subtotal"> <span class="amount">${car.money}</span> </td> </tr> </c:forEach> <tr> <td class="actions" colspan="6"> <div class="coupon"> <label for="coupon_code">优惠券:</label> <input type="text" placeholder="Coupon code" value="" id="coupon_code" class="input-text" name="coupon_code"> <input type="submit" value="Apply Coupon" name="apply_coupon" class="button"> </div> <input type="submit" value="Update Cart" name="update_cart" class="button"> </td> </tr> </tbody> </table> </form>
/** * 跟新购物车商品 * @param String flag 标记, 1表示跳转到修改页面,2表示执行修改操作 * @param Goods goods 要修改商品的对象 * @param ModelAndView mv * */ @RequestMapping(value="/goods/updateCar") public ModelAndView updateCar(Integer pageIndex, String flag, HttpSession session, HttpServletRequest request, ModelAndView mv, Model model){ PageModel pageModel = new PageModel(); if(pageIndex != null){ pageModel.setPageIndex(pageIndex); } /************跟新商品的数量金额***************/ Car car = new Car(); User user = (User) session.getAttribute(CtguConstants.USER_SESSION); if(user != null) { //查找该用户的所有购物单 car.setUserid(user.getId()); } else{ System.out.println("该用户尚未登入!!!!"); } List<Car> cars = carService.findCar(car, pageModel); //查找该用户的购物车中所有商品 String[] nums = request.getParameterValues("num"); //获得需要跟新的数量 System.out.println("获得的字符串为:::: " + nums.toString()); List<Integer> numlist = null; for(String str : nums) { System.out.println(Integer.valueOf(str)); } int len = nums.length; for(int i = 0; i < len; i++) { //跟新数量和总价 System.out.println("新的数量: " + Integer.valueOf(nums[i])); cars.get(i).setNum(Integer.valueOf(nums[i])); cars.get(i).setMoney(cars.get(i).getDanjia() * Integer.valueOf(nums[i])); carService.modifyCar(cars.get(i)); } //执行修改操作 System.out.println("\n修改=== /goods/updateCar == 2"); model.addAttribute("cars", cars); // 设置客户端跳转到查询请求 mv.setViewName("redirect:/goods/carshow"); // 返回 return mv; }
原文地址:https://www.cnblogs.com/zhumengdexiaobai/p/10261089.html
时间: 2024-10-24 08:50:52