论坛首页 入门技术论坛

请教:ibatis中一对多,resultMap中result标签的写法

浏览 8880 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-04-02  
	
		
<resultMap class="EntityA" id="EntityA"> //父表
	<result column= "column1" property="property1" />
	<result column= "column2" property="property2" />
	<result property="columnList"    column="{property3=column3,property4=column4}" select="select2"/>	
</resultMap>

<resultMap class="EntityB" id="EntityB"> //子表
	<result column= "column3" property="property3" />
	<result column= "column4" property="property4" />
	<result column= "column5" property="property5" />
</resultMap>

<select id="select1" parameterClass="java.lang.String" resultMap="EntityA">
	<![CDATA[ 
		SELECT 
			column1,column2
			
		FROM
			table1
		WHERE
			table1.column3 = #property3#
			table1.column4 = #property4#
	]]>	
</select>

<select id="select2" parameterClass="java.lang.String" resultMap="DisplayTabInfoEntity">
	<![CDATA[ 
		SELECT 
			column3,
			column4,
			
			column5
		FROM
			table2
		WHERE
			table2.column3 = #property3#
			table2.column4 = #property4#
		
  	]]>	
	</select>
  如上。这么写可以么?
		
	

	
		
		
		
	
	
		
	

	
		
	


如上。这么写可以么

 

   发表时间:2008-04-02  
为什么不直接用sql的join呢,
resultMap有个属性叫groupBy,专门做这个事情的
0 请登录后投票
   发表时间:2008-04-03  
    <resultMap id="billCardResult" class="BillCard" groupBy="cardId">
       <result property="cardId" column="card_id" />
       <result property="cardCode" column="card_code" />
       <result property="cardName" column="CARD_NAME" />
       <result property="cardCodeLength" column="CODE_LENGTH" />
       <result property="cardType" column="CARD_TYPE" />
       <result property="cardTypeName" column="CARD_NAME" />
       <result property="cardDescription" column="CARD_DESC" />
       <result property="personalDrawLimit" column="LIMIT_DRAW" />
       <result property="isVoucher" column="IS_VOUCHER" />
       <result property="isImport" column="IS_IMPORT" />
       <result property="returnLimit" column="LIMIT_RETURN" />
       <result property="hasCheckCode" column="HAS_CHECK_CODE" />
       <result property="codeRelation" column="CODE_RELA" />
       <result property="otherCode" column="OTHRE_CODE" nullValue=""/>
       <result property="status" column="STATUS" />
       <result property="createDate" column="CREATE_DATE" />
       <result property="createUserId" column="CREATED_BY" />
       <result property="updateDate" column="UPDATE_DATE" />
       <result property="updateUserId" column="UPDATED_BY" /> 
       <result property="premiumSum" column="PREMIUM_SUM" /> 
       <result property="billCardProductList" resultMap="BillCardDefinition.billCardProductResult" nullValue="null"/>  
    </resultMap>

<resultMap id="billCardProductResult" class="BillCardProduct">
       <result property="cardId" column="billCardProduct_card_id" />
       <result property="productId" column="PRODUCT_ID" />
       <result property="policyAmount" column="POLICY_AMOUNT" />
       <result property="premium" column="PREMIUM" />
       <result property="unit" column="UNIT" />
       <result property="productLevel" column="PRODUCT_LEVEL" />
       <result property="coverageTermId" column="COVERAGETERMID" />
       <result property="coveragePeriod" column="COVERAGEPERIOD" />
       <result property="paymentTermId" column="PAYMENTTERMID" />
       <result property="paymentPeriod" column="PAYMENTPERIOD" />
       <result property="paymentType" column="PAYMENTTYPE" />
       <!-- <result property="productId" column="PRODUCT_ID" /> -->
    </resultMap> 

    <select id="getBillCardById" parameterClass="Long" resultMap="billCardResult">
       select billCard.*,billCardProduct.*,billCardProduct.card_id as billCardProduct_card_id
        from t_billcard billCard
        join T_BILLCARD_TYPE billCardType on billCard.Card_Type=billCardType.Card_Type
        left join t_billcard_product billCardProduct on billCard.Card_Id=billCardProduct.Card_Id
        where billCard.status='Y'
        and billCard.Card_Id=#value#
        order by billCard.card_code asc
    </select>

自己看吧,看不懂再看看iBATIS的文档。
0 请登录后投票
   发表时间:2008-04-03  
搞定,谢谢大家
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics