美文网首页java大搜罗
ssm-购物车实现2-jt-cart

ssm-购物车实现2-jt-cart

作者: ssttIsme | 来源:发表于2018-10-22 20:12 被阅读49次
    package com.jt.cart.controller;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import com.jt.cart.service.CartService;
    import com.jt.common.po.Cart;
    import com.jt.common.vo.SysResult;
    
    @Controller
    @RequestMapping("/cart")
    public class CartController {
        @Autowired
        private CartService cartService;
        //根据用户id查询购物车信息
        @RequestMapping("/query/{userId}")
        @ResponseBody
        public SysResult findCartByUserId(@PathVariable Long userId){
            try {
                List<Cart> cartList=cartService.findCartByUserId(userId);
                return SysResult.oK(cartList);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return SysResult.build(201, "购物车信息查询失败");
        }
    }
    
    
    package com.jt.cart.service;
    
    import java.util.List;
    
    import com.jt.common.po.Cart;
    
    public interface CartService {
    
        List<Cart> findCartByUserId(Long userId);
    
    }
    
    
    package com.jt.cart.service;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    import com.jt.cart.mapper.CartMapper;
    import com.jt.common.po.Cart;
    @Service
    public class CartServiceImpl implements CartService {
        @Autowired
        private CartMapper cartMapper;
    
        @Override
        public List<Cart> findCartByUserId(Long userId) {
            Cart cart=new Cart();
            cart.setUserId(userId);
            return cartMapper.select(cart);
        }
    }
    

    http://cart.jt.com/cart/query/7

    相关文章

      网友评论

        本文标题:ssm-购物车实现2-jt-cart

        本文链接:https://www.haomeiwen.com/subject/zhigzftx.html