Composite Keys or Multiple Complex Parameters Properties
You might have noticed that in the above examples there is only a single key being used as specified in the resultMap by the column attribute. This would suggest that only a single column can be associated to a related mapped statement. However, there is an alternate syntax that allows multiple columns to be passed to the related mapped statement. This comes in handy for situations where a composite key relationship exists, or even if you simply want to use a parameter of some name other than #value#. The alternate syntax for the column attribute is simply {param1=column1, param2=column2, …, paramN=columnN}. Consider the example below where the PAYMENT table is keyed by both Customer ID and Order ID:
Example. Mapping a composite key
<resultMaps>
<resultMap id="select-order-result" class="order">
<result property="id" column="ORD_ID"/>
<result property="customerId" column="ORD_CST_ID"/>
…
<result property="payments" column="itemId=ORD_ID, custId=ORD_CST_ID" select="selectOrderPayments"/>
</resultMap>
<resultMaps>
<statements>
<statement id="selectOrderPayments" resultMap="select-payment-result">
select
*
from
PAYMENT
where
PAY_ORD_ID = #itemId#
and
PAY_CST_ID = #custId#
</statement>
</statements>
댓글 없음:
댓글 쓰기