mybatis 一对多映射,
(一) 定义resultMap
<resultMap id="MyResultMap" type="com.bingo.cloud.bingocloud.entity.VMInstance">
<result column="id" jdbcType="VARCHAR" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<collection property="ipAddressList" ofType="java.lang.String"
select="findIpAddress" column="{instanceId=id}">
</collection>
</resultMap>
(二) 查询语句。两个
<select id="findIdaAndNameMap" resultMap="MyResultMap">
SELECT
i.instanceId AS id,
i.instanceName AS NAME
FROM
instance i
</select>
<select id="findIpAddress" resultType="java.lang.String">
select ip.ip from ip_address ip
where ip.instanceId=#{instanceId}
</select>
(三) mapper 接口
List<VMInstance> findIdaAndNameMap();
这样就行了