• 删除购物车列表页面商品


    一、实现思路

      1、从前台页面传进来itemId。

      2、从cookie中取所有商品的列表。

      3、删除itemId对应的商品。

      4、将商品列表再传回cookie中,并响应给浏览器。

    二、jsp页面删除代码

      1、请求url : /cart/delete/${cart.id}.html

    <div class="cell p-remove"><a id="remove-11345721-1" data-more="removed-87.20-1" clstag="clickcart|keycount|xincart|btndel318558" class="cart-remove" href="/cart/delete/${cart.id}.html">删除</a>

    三、service层代码

    @Service
    public class CartServiceImpl implements CartService {
    
        @Autowired
        private ItemService itemService;
        @Value("${COOKIE_EXPIRE}")
        private Integer COOKIE_EXPIRE;
    
       ......
    
        @Override
        public TaotaoResult deleteCartItem(Long itemId, HttpServletRequest request, HttpServletResponse response) {
            List<CartItem> lists = getCartLists(request);
            for (CartItem c : lists) {
                if(c.getId().longValue() == itemId) {
                    lists.remove(c);
                    break;
                }
            }
            CookieUtils.setCookie(request, response,"TT_CART",JsonUtils.objectToJson(lists), COOKIE_EXPIRE, true);
            return TaotaoResult.ok();
        }
    }

    四、controller层代码,重定向到cart.jsp页面。

    @Controller
    public class CartController {
    
        @Autowired
        private CartService cartService;
      .......
    @RequestMapping("/cart/cart") public String showCart(HttpServletRequest request, Model model) { List<CartItem> cartLists = cartService.getCartLists(request); model.addAttribute("cartList", cartLists); return "cart"; } ....... @RequestMapping("/cart/delete/{itemId}") public String deleteCartItem(@PathVariable Long itemId,HttpServletRequest request,HttpServletResponse response) { cartService.deleteCartItem(itemId, request, response); return "redirect:/cart/cart.html"; } }
  • 相关阅读:
    实现发送邮件
    c#操作sqlite(包含中文支持)
    C# & SQLite
    卸载impala
    kudu集成impala
    Kudu的卸载(cdh)
    Kudu的集群安装(1.6.0-cdh5.14.0)
    ELK日志平台搭建
    logstash之OutPut插件
    logstash之Filter插件
  • 原文地址:https://www.cnblogs.com/huclouy/p/9500563.html
Copyright © 2020-2023  润新知