mybatis一对多关系映射问题

在用mybatis做一对多的关系映射时,发现只能映射到一个实体。
仔细看文档发现:

http://www.mybatis.org/mybatis-3/sqlmap-xml.html

In these cases MyBatis is automatically creating a ResultMap behind the scenes to auto-map the columns to the JavaBean properties based on name. If the column names did not match exactly, you could employ select clause aliases (a standard SQL feature) on the column names to make the labels match.

如果两个连接表的主键起名一样,这里指的是列的别名,既不是数据库字段名,也不是实体名,这里指:column=detailId。
如果一样,则只能形成1对1的映射。
另外,要注意resultMap中的column值要和select语句中的字段别名一样,否则该字段指产出来为空。

<resultMap id="SettleInfoDetailRP" type="com.ctrip.group.bnb.merchantws.core.model.SettleInfoDetail">
    <id column="*detailId*" jdbcType="INTEGER" property="id"/>
    <result column="reverseFlag" jdbcType="INTEGER" property="reverseFlag"/>
    <result column="transId" jdbcType="INTEGER" property="transId"/>
    <result column="origTransId" jdbcType="INTEGER" property="origTransId"/>
    <result column="detailBatchNo" jdbcType="VARCHAR" property="detailBatchNo"/>
    <result column="transAmount" jdbcType="DOUBLE" property="transAmount"/>
    <result column="purchaseAmount" jdbcType="DOUBLE" property="purchaseAmount"/>
    <result column="onlinePurchaseAmount" jdbcType="DOUBLE" property="onlinePurchaseAmount"/>
    <result column="offlinePurchaseAmount" jdbcType="DOUBLE" property="offlinePurchaseAmount"/>
    <result column="onlineFeeAmount" jdbcType="DOUBLE" property="onlineFeeAmount"/>
    <result column="offlineFeeAmount" jdbcType="DOUBLE" property="offlineFeeAmount"/>
    <result column="feeAmount" jdbcType="DOUBLE" property="feeAmount"/>
    <result column="feeCalFormula" jdbcType="VARCHAR" property="feeCalFormula"/>
    <result column="bscUpdateTime" jdbcType="TIMESTAMP" property="updateTime"/>
    <result column="bscUpdateTime" jdbcType="TIMESTAMP" property="version"/>

    <association property="order" resultMap="orderResultMap"/>
</resultMap>


<resultMap id="SettleSumRP" type="com.ctrip.group.bnb.merchantws.core.model.SettleSummary">
    <id column="**id**" jdbcType="INTEGER" property="id"/>
    <result column="batchNo" jdbcType="VARCHAR" property="batchNo"/>
    <result column="merchantType" jdbcType="INTEGER" property="merchantType"/>
    <result column="merchantCode" jdbcType="VARCHAR" property="merchantCode"/>
    <result column="transCount" jdbcType="INTEGER" property="transCount"/>
    <result column="transAmount" jdbcType="DOUBLE" property="transAmount"/>
    <result column="capCdFlag" jdbcType="INTEGER" property="capCdFlag"/>
    <result column="feeAmount" jdbcType="DOUBLE" property="feeAmount"/>
    <result column="financeFlag" jdbcType="INTEGER" property="financeFlag"/>
    <result column="feeCdFlag" jdbcType="INTEGER" property="feeCdFlag"/>
    <result column="financeCode" jdbcType="VARCHAR" property="financeCode"/>
    <result column="settlePeriodStartDate" jdbcType="TIMESTAMP" property="settlePeriodStartDate"/>
    <result column="settlePeriodEndDate" jdbcType="TIMESTAMP" property="settlePeriodEndDate"/>

    <collection property="settleInfoDetailList" ofType="com.ctrip.group.bnb.merchantws.core.model.SettleInfoDetail" resultMap="SettleInfoDetailRP"/>
</resultMap>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值