src/cn/itbaizhan/shop/cart/action/CartAction.java
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
package cn.itbaizhan.shop.cart.action;
import org.apache.struts2.ServletActionContext;
import cn.itbaizhan.shop.cart.vo.Cart;
import cn.itbaizhan.shop.cart.vo.CartItem;
import cn.itbaizhan.shop.product.service.ProductService;
import cn.itbaizhan.shop.product.vo.Product;
import com.opensymphony.xwork2.ActionSupport;
/**
* 购物车Action
*/
public class CartAction extends ActionSupport {
// 接收pid
private Integer pid;
// 接收数量count
private Integer count;
// 注入商品的Service
private ProductService productService;
public void setProductService(ProductService productService) {
this.productService = productService;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public void setCount(Integer count) {
this.count = count;
}
// 将购物项添加到购物车:执行的方法
public String addCart() {
// 封装一个CartItem对象.
CartItem cartItem = new CartItem();
// 设置数量:
cartItem.setCount(count);
// 根据pid进行查询商品:
Product product = productService.findByPid(pid);
// 设置商品:
cartItem.setProduct(product);
// 将购物项添加到购物车.
// 购物车应该存在session中.
Cart cart = getCart();
cart.addCart(cartItem);
return "addCart";
}
// 清空购物车的执行的方法:
public String clearCart(){
// 获得购物车对象.
Cart cart = getCart();
// 调用购物车中清空方法.
cart.clearCart();
return "clearCart";
}
后面还有 31 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。