1 回答
TA贡献1770条经验 获得超3个赞
不完全是这样,但它可以帮助找到解决方案。有相应的要求:
@Select("Select c.id, c.name, c.towerid, s.id as s_id, s.size as s_size, s.type as s_type, s.computer_id as s_computer_id from computer c left join screen s ON s.computer_id = c.id where c.id=#{computerId}")
@ResultMap("ComputerMapper.computer")
public Computer getcomputerById(@Param("computerId") Integer computerId);
这是结果图:
<resultMap type="entity.Computer" id="computer">
<id column="id" property="id"/>
<result column="name" property="name"/>
<association property="tower" column="towerid" javaType="entity.Tower" select="getTowerbycomputerid"/>
<collection ofType="entity.Screen" property="screen" javaType="ArrayList" resultMap="screenResult" columnPrefix="s_"/>
</resultMap>
现在 resultMap 和获取塔的请求:
<resultMap id="towerResult" type="entity.Tower">
<id property="id" column="id"/>
<result property="ram" column="ram"/>
<result property="stockage" column="stockage"/>
</resultMap>
<select id="getTowerbycomputerid" resultMap="towerResult">
Select t.id, t.ram, t.stockage from tower t where t.id = #{towerid}
</select>
现在一切正常。在得到这个来选择塔之前:
<select id="getTowerbycomputerid" resultMap="towerResult">
Select t.id, t.ram, t.stockage from tower t inner join computer c on c.towerid = t.id where c.id = #{computerId}
</select>
这就是结局。
添加回答
举报