继承父类的resultMap
,然后父类有的那一部分属性标签(id、result标签)就不用自己写了,例如:
子类:
public class PromotionProduct extends PmsProduct {
//商品库存信息
private List<PmsSkuStock> skuStockList;
//商品打折信息
private List<PmsProductLadder> productLadderList;
//商品满减信息
private List<PmsProductFullReduction> productFullReductionList;
……
}
父类:
public class PmsProduct implements Serializable {
private Long id;
private Long brandId;
private Long productCategoryId;
……
}
XXXMapper.xml:
<mapper namespace="com.macro.mall.mapper.PmsProductMapper">
<resultMap id="BaseResultMap" type="com.macro.mall.model.PmsProduct">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="brand_id" jdbcType="BIGINT" property="brandId" />
<result column="product_category_id" jdbcType="BIGINT" property="productCategoryId" />
…………
</resultMap>
<resultMap id="promotionProductMap" type="com.macro.mall.portal.domain.PromotionProduct" extends="com.macro.mall.mapper.PmsProductMapper.BaseResultMap">
<id column="id" jdbcType="BIGINT" property="id" />
<collection property="skuStockList" columnPrefix="sku_" resultMap="com.macro.mall.mapper.PmsSkuStockMapper.BaseResultMap">
</collection>
<collection property="productLadderList" columnPrefix="ladder_" resultMap="com.macro.mall.mapper.PmsProductLadderMapper.BaseResultMap">
</collection>
<collection property="productFullReductionList" columnPrefix="full_" resultMap="com.macro.mall.mapper.PmsProductFullReductionMapper.BaseResultMap">
</collection>
</resultMap>
</mapper>
说明:
PromotionProduct
对应第2个resultMap
标签,PmsProduct
对应第1个resultMap
标签,其中PromotionProduct
类继承了PmsProduct
类,那么按理来说第2个resultMap
标签应该写上所有的的属性,包括从PmsProduct
中继承过来的属性,不过我们已经写了第1个resultMap
标签,对于那些从PmsProduct
中继承过来的属性,直接使用extends
属性继承一下就可以 了