XML 映射:
3.2.7+ -> fetchType 属性(懒惰/渴望)
<resultMap id="itemResultMap" type="Item">
<id property="id" column="id"/>
<association property="subItem" column="subItemId" javaType="SubItem"
select="selectSubItemByIdQuery" fetchType="lazy"/>
</resultMap>
@注解映射:
@Select({"SELECT * FROM item WHERE id = #{id}"})
@Results({
@Result(property = "id", column = "id"),
@Result(property = "subItem", column = "subItemId", javaType = SubItem.class,
one = @One(select = "SubItemMapper.getById",
fetchType = FetchType.LAZY))
})
Item getById(int id);