标题:
ssm-购物车实现(1)
[打印本页]
作者:
look_w
时间:
2019-3-14 19:34
标题:
ssm-购物车实现(1)
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, "购物车信息查询失败");
}
@RequestMapping("/save")
//实现购物车入库
public SysResult saveCart(Cart cart){
try {
cartService.saveCart(cart);
return SysResult.oK();
} catch (Exception e) {
// TODO: handle exception
}
return SysResult.build(201, "购物车新增失败");
}
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0