collection用法:
<resultMap id="classifyMap" type="com.xxx.xx.x.x.x.ClassifyList">
<id property="id" column="id"/>
<result property="classifyTitle" column="classify_title"/>
<result property="classifyDesc" column="classify_desc"/>
<collection property="seriesList" ofType="com.xxx.xx.x.x.x.ArticleEntity">
<id property="id" column="id"/>
<result property="title" column="title"/>
<result property="desc" column="desc"/>
<result property="imageUrl" column="image_url"/>
</collection>
</resultMap>
如果是非自定义collection:注意ofType中的值
<resultMap id="getArticleEsResultMap" type="com.xxx.xx.x.ArticleInfoEntity">
<result property="id" column="id"/>
<result property="title" column="title"/>
<collection property="tagIdList" ofType="int" javaType="list">
<result column="tagId" />
</collection>
</resultMap>
columnPrefix用法:作为列名前缀
<resultMap id="homework" type="com.xxx.xx.x.HomeworkEntity" autoMapping="true">
<id property="id" column="id"/>
<collection property="homeworkItemEntityList" ofType="com.xxx.xx.x.HomeworkItemEntity" columnPrefix="item_" autoMapping="true"/>
</resultMap>
子查询用法:内嵌子查询(获取单词释义)
<resultMap id="getWordListResultMap" type="com.qzh.entity.GetCatalogWordListEn">
<result property="wordId" column="id"/>
<result property="word" column="word"/>
<collection property="meanings" column="id"
ofType="com.zhl.res.pojo.study.english.dict.MeaningsEn" select="getMeanings"/>
</resultMap>
<resultMap id="meanings" type="com.qzh.dict.MeaningsEn">
<result property="pos" column="pos"/>
<collection property="meaning" column="meaning" ofType="string" javaType="list">
<result column="meaning" />
</collection>
</resultMap>
<select id="getCatalogWordList" resultMap="getWordListResultMap">
select id ,word from book_word a
where a.`status` = 0
and a.catalog_id in
<foreach collection="list" open="(" separator="," close=")" item="item">
#{item}
</foreach>
order by a.sort
</select>