mybatis中resultMap标签中的extends属性有什么用?
继承父类的resultMap,然后父类有的那一部分属性标签(id、result标签)就不用自己写了,例如:子类:public class PromotionProduct extends PmsProduct {//商品库存信息private List<PmsSkuStock> skuStockList;//商品打折信息private List<PmsProductLadder&
·
继承父类的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属性继承一下就可以 了
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)