在用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>