Mybatis ResultMap Collection 复合主键

时间:2022-10-12 17:58:45

<resultMap type="XX" id="XXMap">  
        <id property="id" column="colid"/>

<id property="name" column="colname"/>

<collection property="list" javaType="ArrayList" column="{id = colid,name=colname}" select="getSubXXX"/>
 </resultMap>

前为别名后为主查询getXXX语句中字段

<select id="getXXX" parameterType="HashMap" resultMap="XXX">  
        SELECT colid,colname FROM table1

</select>

<select id="getSubXXX" parameterType="HashMap" resultType="XXX">  
        SELECT * FROM table2 WHERE id = #{id} AND name = #{name}
  </select>