想让数据库返回 SkuItemSaleAttrVo 实体数据
@ToString @Data public class SkuItemSaleAttrVo { private Long attrId; private String attrName; private List<AttrValueWithSkuIdVo> attrValues; }
@Data @ToString public class AttrValueWithSkuIdVo { private String attrValue; private String skuIds; }
定义Mapper
List<SkuItemSaleAttrVo> getSaleAttrsBySpuId(@Param("spuId") Long spuId);
定义Dao.xml
<resultMap id="skuItemSaleAttrVo" type="com.feng.mall.product.vo.SkuItemSaleAttrVo"> <result column="attr_id" property="attrId"></result> <result column="attr_name" property="attrName"></result> <collection property="attrValues" ofType="com.feng.mall.product.vo.AttrValueWithSkuIdVo"> <result column="attr_value" property="attrValue"></result> <result column="sku_ids" property="skuIds"></result> </collection> </resultMap> <select id="getSaleAttrsBySpuId" resultMap="skuItemSaleAttrVo"> select ssav.attr_id, ssav.attr_name, ssav.attr_value, group_concat(distinct info.sku_id) sku_ids from pms_sku_info info left join pms_sku_sale_attr_value ssav on ssav.sku_id = info.sku_id where info.spu_id = #{spuId} group by ssav.attr_id, ssav.attr_name, ssav.attr_value </select>