|
|
package com.yj.bean;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
/**
|
|
|
* @author yj
|
|
|
* @create 2020-08-26 20:08
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
* 购物车商品项
|
|
|
*/
|
|
|
// 定义一个名为CartItem的类,代表购物车中的一个商品项
|
|
|
public class CartItem {
|
|
|
// 定义一个私有变量id,用于存储商品的唯一标识符
|
|
|
private Integer id;
|
|
|
// 定义一个私有变量name,用于存储商品的名称
|
|
|
private String name;
|
|
|
// 定义一个私有变量count,用于存储商品的数量
|
|
|
private Integer count;
|
|
|
// 定义一个私有变量price,用于存储商品的单价,使用BigDecimal类型以支持精确的小数计算
|
|
|
private BigDecimal price;
|
|
|
// 定义一个私有变量totalPrice,用于存储商品的总价(单价乘以数量),同样使用BigDecimal类型
|
|
|
private BigDecimal totalPrice;
|
|
|
|
|
|
// 定义一个公开的getter方法,用于获取商品的id
|
|
|
public Integer getId() {
|
|
|
return id;
|
|
|
}
|
|
|
// 定义一个公开的setter方法,用于设置商品的id
|
|
|
public void setId(Integer id) {
|
|
|
this.id = id;
|
|
|
}
|
|
|
// 定义一个公开的getter方法,用于获取商品的名称
|
|
|
public String getName() {
|
|
|
return name;
|
|
|
}
|
|
|
// 定义一个公开的setter方法,用于设置商品的名称
|
|
|
public void setName(String name) {
|
|
|
this.name = name;
|
|
|
}
|
|
|
// 定义一个公开的getter方法,用于获取商品的数量
|
|
|
public Integer getCount() {
|
|
|
return count;
|
|
|
}
|
|
|
// 定义一个公开的setter方法,用于设置商品的数量
|
|
|
public void setCount(Integer count) {
|
|
|
this.count = count;
|
|
|
}
|
|
|
// 定义一个公开的getter方法,用于获取商品的单价
|
|
|
public BigDecimal getPrice() {
|
|
|
return price;
|
|
|
}
|
|
|
// 定义一个公开的setter方法,用于设置商品的单价
|
|
|
public void setPrice(BigDecimal price) {
|
|
|
this.price = price;
|
|
|
}
|
|
|
// 定义一个公开的getter方法,用于获取商品的总价
|
|
|
public BigDecimal getTotalPrice() {
|
|
|
return totalPrice;
|
|
|
}
|
|
|
// 定义一个公开的setter方法,用于设置商品的总价
|
|
|
public void setTotalPrice(BigDecimal totalPrice) {
|
|
|
this.totalPrice = totalPrice;
|
|
|
}
|
|
|
|
|
|
// 定义一个公开的构造方法,用于创建CartItem对象并初始化其所有属性
|
|
|
public CartItem(Integer id, String name, Integer count, BigDecimal price, BigDecimal totalPrice) {
|
|
|
// 使用this关键字将传入的id参数赋值给当前对象的id属性
|
|
|
this.id = id;
|
|
|
// 设置商品的唯一标识符
|
|
|
|
|
|
// 使用this关键字将传入的name参数赋值给当前对象的name属性
|
|
|
this.name = name;
|
|
|
// 设置商品的名称
|
|
|
|
|
|
// 使用this关键字将传入的count参数赋值给当前对象的count属性
|
|
|
this.count = count;
|
|
|
// 设置商品的数量
|
|
|
|
|
|
// 使用this关键字将传入的price参数赋值给当前对象的price属性
|
|
|
this.price = price;
|
|
|
// 设置商品的单价,使用BigDecimal类型以支持精确的小数计算
|
|
|
|
|
|
// 使用this关键字将传入的totalPrice参数赋值给当前对象的totalPrice属性
|
|
|
this.totalPrice = totalPrice;
|
|
|
// 设置商品的总价(单价乘以数量),同样使用BigDecimal类型
|
|
|
}
|
|
|
// 定义一个无参构造方法,用于创建CartItem对象时不初始化任何属性
|
|
|
public CartItem() {
|
|
|
}
|
|
|
|
|
|
// 重写toString方法,用于返回CartItem对象的字符串表示形式
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
// 返回的字符串包含CartItem对象的所有属性信息
|
|
|
return "Cart{" +
|
|
|
"id=" + id +
|
|
|
// 显示商品的id
|
|
|
", name='" + name + '\'' +
|
|
|
// 显示商品的名称
|
|
|
", count=" + count +
|
|
|
// 显示商品的数量
|
|
|
", price=" + price +
|
|
|
// 显示商品的单价
|
|
|
", totalPrice=" + totalPrice +
|
|
|
// 显示商品的总价
|
|
|
'}';
|
|
|
}
|
|
|
}
|