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