日期:2014-05-16  浏览次数:20395 次

ibatis中使用extends实现继承

?

1. 场景

MarketingProductDO和ExportMarketingProductDO都继承AbstractMarketingProductDO(抽象类);

?

?

2. 配置

AbstractMarketingActivityResult:

 	<resultMap id="abstractMarketingActivityResult" class="abstractMarketingProductDO" >
		<result property="Id" column="id" jdbcType="NUMBER"
			javaType="java.lang.Long" />
		<result property="productName" column="product_name" jdbcType="VARCHAR"
			javaType="java.lang.String" />
		<result property="productImgUrl" column="product_img_url" jdbcType="VARCHAR"
			javaType="java.lang.String" />	
		<result property="productDetailUrl" column="product_detail_url" jdbcType="VARCHAR"
			javaType="java.lang.String" />		
		<result property="sellerNickName" column="seller_nick_name" jdbcType="VARCHAR"
			javaType="java.lang.String" />				
	</resultMap>		

?

?

MarketingProductActivity4ExportResult:

?

	<resultMap id="marketingProductActivity4ExportResult" class="exportMarketingProductDO" extends="abstractMarketingActivityResult">
		<result property="activityName" column="activity_name" jdbcType="VARCHAR"
			javaType="java.lang.String" />	
		<result property="startDate" column="start_date" jdbcType="DATETIME"
			javaType="java.util.Date" />
		<result property="endDate" column="end_date" jdbcType="DATETIME"
			javaType="java.util.Date" />
		<result property="activityCreator" column="activity_creator" jdbcType="VARCHAR"
			javaType="java.lang.String" />	
		<result property="curPrice" column="cur_price" jdbcType="NUMBER"
			javaType="java.lang.Double" />		
		<result property="discountPrice" column="discount_Price" jdbcType="NUMBER"
			javaType="java.lang.Double" />	
	</resultMap>
?

?

?

3. 注意

?1)resultMap必须extends resultMap

?2) MarketingProductActivity4ExportResult?这个必须配置在AbstractMarketingActivityResult后面,否则会报错

?