这里应该不用改吧 下面不是 as了吗 我改成img_addr 查出的图片 是商品图片 不是详情图片
detail_img<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.imooc.o2o.dao.ProductDao">
<resultMap id="productMap" type="com.imooc.o2o.entity.Product">
<id column="product_id" property="productId"/>
<result column="product_name" property="productName"/>
<result column="product_desc" property="productDesc"/>
<result column="img_addr" property="imgAddr"/>
<result column="normal_price" property="normalPrice"/>
<result column="promotion_price" property="promotionPrice"/>
<result column="priority" property="priority"/>
<result column="create_time" property="createTime"/>
<result column="last_edit_time" property="lastEditTime"/>
<result column="enable_status" property="enableStatus"/>
<association property="productCategory" column="product_category_id" javaType="com.imooc.o2o.entity.ProductCategory">
<id column="product_category_id" property="productCategoryId"/>
<result column="product_category_name" property="productCategoryName"/>
</association>
<association property="shop" column="shop_id" javaType="com.imooc.o2o.entity.Shop">
<id column="shop_id" property="shopId"/>
<result column="owner_id" property="ownerId"/>
<result column="shop_name" property="shopName"/>
</association>
<collection property="productImgList" column="product_id" ofType="com.imooc.o2o.entity.ProductImg">
<id column="product_img_id" property="productImgId"/>
<result column="img_addr" property="imgAddr"/>
<result column="img_desc" property="imgDesc"/>
<result column="priority" property="priority"/>
<result column="create_time" property="createTime"/>
<result column="product_id" property="productId"/>
</collection>
</resultMap>
<select id="queryProductById" resultMap="productMap" parameterType="Long">
<!-- 具体的sql -->
SELECT
p.product_id,
p.product_name,
p.product_desc,
p.img_addr,
p.normal_price,
p.promotion_price,
p.priority,
p.create_time,
p.last_edit_time,
p.enable_status,
# TODO p.point,
p.product_category_id,
p.shop_id,
pm.product_img_id,
pm.img_addr AS detail_img,
pm.img_desc,
pm.priority AS pm_priority,
pm.create_time
FROM
tb_product p
LEFT JOIN
tb_product_img pm
ON
p.product_id =
pm.product_id
WHERE
p.product_id =
#{productId}
ORDER BY
pm.priority DESC
</select>
@Test
public void testQuertByProductId(){
Long productId = 57l;
Product product = productDao.queryProductById(productId);
System.out.println(product.getProductImgList().size());
System.out.println(product.getProductImgList().get(0).getImgAddr());
System.out.println(product.getProductImgList().get(1).getImgAddr());
System.out.println(product.getShop().getShopId());
}
25
收起
正在回答 回答被采纳积分+1
2回答
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星