我是MyBatis的新手,所以如果有人可以帮我解决我的问题,那就太想了。 问题围绕着电视节目。
物件
映射
选择查询
<select id="findsProgramGuideDetails" resultMap="programGuideDetails" parameterType="map">
select
sourceCode, showCode, productNumber, programTitle, OTHER_FIELDS
from MY_TABLE where SOME_CONDITIONS
</select>
结果地图
<resultMap id="programGuideDetails" type="com.qvc.integration.batch.programguide.vo.UdbProgramGuideDataloadDetailsVo">
<id property="sourceCode" column="sourceCode"
typeHandler="com.test.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
<result property="showCode" column="showCode"
typeHandler="com.test.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
<result property="programTitle" column="programTitle"
typeHandler="com.test.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
... Other Result tags
在Resultmap中收集
<collection property="plannedShows" ofType="com.test.programguide.dataload.model.vo.PlannedShow" column="programTitle">
<id property="showTitle" column="programTitle"
typeHandler="com.test.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
<result property="id" column="sourceCode"
typeHandler="com.test.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
<result property="channelCode" column="channel"
typeHandler="com.test.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
<result property="startDate" column="startDate"
typeHandler="com.test.integration.batch.programguide.typehandler.DateFormatTypeHandler" />
<result property="endDate" column="endDate"
typeHandler="com.test.integration.batch.programguide.typehandler.DateFormatTypeHandler" />
</collection>
<collection property="productDetails" ofType="com.qvc.programguide.dataload.model.vo.ProductDetail" column="sourceCode">
<id property="productId" column="productNumber"
typeHandler="com.qvc.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
<result property="productName" column="productName"
typeHandler="com.qvc.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
<result property="brandId" column="brandId"
typeHandler="com.qvc.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
<result property="brandName" column="brandName"
typeHandler="com.qvc.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
<result property="priceCode" column="priceCode"
typeHandler="com.qvc.integration.batch.programguide.typehandler.StringTrimmingTypeHandler" />
</collection>
问题
每个唱片都会正常播放多个产品,但计划中的电视节目,即之前和即将播放的重复电视广播仅仅是为了获取。
答案 0 :(得分:0)
关系一对多很简单,使用集合标记并定义参数以加入密钥,在这种情况下,我还使用请求参数作为子选择列。
<resultMap type="package.pojo.Recipient" id="receiversResultMap">
<result column="EMAIL_ADDRESS" property="emailAddress" />
<result column="END_TS" property="endTs" />
<result column="NAME" property="name" />
<result column="RECIPIENT_ID" property="recipientId" />
<result column="START_TS" property="startTs" />
<result column="TYPE" property="type" />
<result column="UPDATE_TS" property="updateTs" />
<result column="USER_ID" property="userId" />
<collection property="messages" column="{param1=RECIPIENT_ID, param2=LOCKID}" javaType="ArrayList" ofType="java.util.List" select="findMessages" />
</resultMap>
<select id="findReceivers" resultMap="receiversResultMap">
SELECT
EMAIL_ADDRESS,
END_TS,
NAME,
RECIPIENT_ID,
START_TS,
TYPE,
UPDATE_TS,
USER_ID,
#{lockId} AS LOCKID
FROM T_DOPA0_RECIPIENT
</select>
<resultMap type="package.pojo.Message" id="messageResultMap">
<result column="EMAIL_USED" property="emailUsed" />
<result column="LOCK_ID" property="lockId" />
<result column="MESSAGE_ID" property="messageId" />
<result column="RECEIPT_TS" property="receiptTs" />
<result column="RECIPIENT_ID" property="recipientId" />
<result column="SELECTED" property="selected" />
<result column="SEND_TS" property="sendTs" />
<result column="TYPE" property="type" />
<result column="DESCRIPTION" property="description" />
</resultMap>
<select id="findMessages" resultMap="messageResultMap">
SELECT
EMAIL_USED,
LOCK_ID,
MESSAGE_ID,
RECEIPT_TS,
RECIPIENT_ID,
SELECTED,
SEND_TS,
TYPE,
DECODE.DESCRIPTION
FROM T_MESSAGE MESSAGE
LEFT OUTER JOIN D_MESSAGE_TYPE DECODE ON DECODE.LOCK_MESSAGE_TYPE = MESSAGE.TYPE
WHERE RECIPIENT_ID = '${param1}'
AND LOCK_ID = '${param2}'
</select>