JAVA全系列 教程
3762个小节阅读:7088.2k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
在通用模块编写商品详情实体类GoodsDesc
xxxxxxxxxx
/**
* 商品详情
*/
@Data
public class GoodsDesc implements Serializable {
private Long id; // 商品id
private String goodsName; // 商品名称
private String caption; // 副标题
private BigDecimal price; // 价格
private String headerPic; // 头图
private Boolean isMarketable; // 是否上架
private String introduction; // 商品介绍
private Brand brand; // 品牌
private ProductType productType1; // 一级类目
private ProductType productType2; // 二级类目id
private ProductType productType3; // 三级类目id
private List<GoodsImage> images; // 商品图片
private List<Specification> specifications; // 商品规格
}
在商品服务模块的Mapper中添加查询所有商品详情方法
xxxxxxxxxx
// 查询所有商品详情
List<GoodsDesc> findAll();
编写Mapper映射文件
xxxxxxxxxx
<resultMap id="goodsDescMapper" type="com.itbaizhan.shopping_common.pojo.GoodsDesc">
<id property="id" column="bid"></id>
<result property="goodsName" column="goodsName"></result>
<result property="caption" column="caption"></result>
<result property="price" column="price"></result>
<result property="headerPic" column="headerPic"></result>
<result property="isMarketable" column="isMarketable"></result>
<result property="introduction" column="introduction"></result>
<association property="brand" column="brandId" javaType="com.itbaizhan.shopping_common.pojo.Brand">
<id property="id" column="brandId"></id>
<result property="name" column="brandName"></result>
</association>
<association property="productType1" column="type1Id" javaType="com.itbaizhan.shopping_common.pojo.ProductType">
<id property="id" column="type1Id"></id>
<result property="name" column="type1Name"></result>
<result property="level" column="type1Level"></result>
<result property="parentId" column="type1ParentId"></result>
</association>
<association property="productType2" column="type2Id" javaType="com.itbaizhan.shopping_common.pojo.ProductType">
<id property="id" column="type2Id"></id>
<result property="name" column="type2Name"></result>
<result property="level" column="type2Level"></result>
<result property="parentId" column="type2ParentId"></result>
</association>
<association property="productType3" column="type3Id" javaType="com.itbaizhan.shopping_common.pojo.ProductType">
<id property="id" column="type3Id"></id>
<result property="name" column="type3Name"></result>
<result property="level" column="type3Level"></result>
<result property="parentId" column="type3ParentId"></result>
</association>
<collection property="images" column="bid" ofType="com.itbaizhan.shopping_common.pojo.GoodsImage">
<id property="id" column="imageId"></id>
<result property="imageTitle" column="imageTitle"></result>
<result property="imageUrl" column="imageUrl"></result>
</collection>
<collection property="specifications" column="bid" ofType="com.itbaizhan.shopping_common.pojo.Specification">
<id property="id" column="specificationId"></id>
<result property="specName" column="specName"></result>
<result property="productTypeId" column="productTypeId"></result>
<collection property="specificationOptions" column="specificationId" ofType="com.itbaizhan.shopping_common.pojo.SpecificationOption">
<id property="id" column="optionId"></id>
<result property="optionName" column="optionName"></result>
</collection>
</collection>
</resultMap>
<select id="findAll" resultMap="goodsDescMapper">
SELECT
bz_goods.id bid,
bz_goods.goodsName goodsName,
bz_goods.caption caption,
bz_goods.price price,
bz_goods.headerPic headerPic,
bz_goods.introduction introduction,
bz_goods.isMarketable isMarketable,
bz_goods.brandId brandId,
bz_brand.`name` brandName,
type1.id type1Id,
type1.`name` type1Name,
type1.`level` type1Level,
type1.parentId type1ParentId,
type2.id type2Id,
type2.`name` type2Name,
type2.`level` type2Level,
type2.parentId type2ParentId,
type3.id type3Id,
type3.`name` type3Name,
type3.`level` type3Level,
type3.parentId type3ParentId,
bz_goods_image.id imageId,
bz_goods_image.imageTitle imageTitle,
bz_goods_image.imageUrl imageUrl,
bz_specification.id specificationId,
bz_specification.specName specName,
bz_specification.productTypeId productTypeId,
bz_specification_option.id optionId,
bz_specification_option.optionName optionName
FROM
bz_goods,
bz_goods_image,
bz_brand,
bz_specification,
bz_specification_option,
bz_goods_specification_option,
bz_product_type AS type1,
bz_product_type AS type2,
bz_product_type AS type3
WHERE bz_goods.id = bz_goods_specification_option.gid
AND bz_goods_specification_option.optionId = bz_specification_option.id
AND bz_specification.id = bz_specification_option.specId
AND bz_goods.brandId = bz_brand.id
AND bz_goods.id = bz_goods_image.goodsId
AND bz_goods.productType1Id = type1.id
AND bz_goods.productType2Id = type2.id
AND bz_goods.productType3Id = type3.id
</select>
修改商品服务接口和实现类
xxxxxxxxxx
public interface GoodsService {
// 查询所有商品详情
List<GoodsDesc> findAll();
}
public class GoodsServiceImpl implements GoodsService {
@Override
public List<GoodsDesc> findAll() {
return goodsMapper.findAll();
}
}