mybatis配置返回集合collection时只有⼀条记录
查询语句配置如下:
<lect id="lectCustomerList" resultMap="CustomerDtoMap" parameterType="map">
lect * from
(
lect <include refid="AliasCustomerColumnList"/>
rsdfrom customer clogogo
) c
left join display_venue_rerve dvr
on c.c_customer_id = dvr.customer_id where 1=1
<if test="customerMgrId != null">
and c.c_customer_mgr_id = #{customerMgrId}
</if>
lution<if test="status != null">
and dvr.status = #{status}
b
</if>
</lect>
resultMap配置如下
<resultMap id="CustomerDtoMap" type="showroom.dto.customer.CustomerDto" extends="AliasBaResultMap">
<collection property="displayVenueRerveDtoList" ofType="showroom.dto.display.DisplayVenueRerveDto">
<association property="displayVenueRerve" column="VENUE_RESERVE_ID" javaType="com.al.
del.display.DisplayVenueRerve" resultMap="showroom.mapper.display.DisplayVenueRerveMapper.BaResultMap">
</association>
英语翻译价格
</collection>
</resultMap>
查询出结果如下:
深圳华尔街英语地址
只有⼀条记录,但是数据库直接执⾏语句是有多条记录的
经过很多轮的改代码研究,发现是因为
<collection property="displayVenueRerveDtoList" ofType="showroom.dto.display.DisplayVenueRerveDto">
<association property="displayVenueRerve" column="VENUE_RESERVE_ID" javaType="del.display.DisplayVenueRerve" resultMap="showroom.mapper.display.DisplayVenueRerveMapper.BaResultMap">
</association>
</collection>
需要在collection节点下添加
presidents<id column="dvr_VENUE_RESERVE_ID" property="venueRerveId" jdbcType="DECIMAL"></id>
深圳心理咨询师培训
更改后代码如下
<resultMap id="CustomerDtoMap" type="showroom.dto.customer.CustomerDto" extends="AliasBaResultMap">
<collection property="displayVenueRerveDtoList" ofType="showroom.dto.display.DisplayVenueRerveDto">
<id column="VENUE_RESERVE_ID" property="venueRerveId" jdbcType="DECIMAL"></id>
<association property="displayVenueRerve" column="VENUE_RESERVE_ID" javaType="del.display.DisplayVenueRerve" resultMap="showroom.mapper.display.DisplayVenueRerveMapper.AliasBaResultMap">headcount什么意思
</association>
</collection>
</resultMap>
英译汉
⼀直以为<association>节点有column属性就可以作为主键就可以了。。。。原来是需要在<collection>下添加id⼦节点查询结果如下
但是对于这样配置的原理还不是很了解,如果知道的⼤神希望能在评论⾥给出回复,感谢
⼩⽩,刚接触mybatis不久,记录在此,谨记于⼼~~