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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容