使用resultMap映射VO对象时:
public class CategoryVO {
private Integer id;
private String name;
private String type;
private Integer fatherId;
// 三级分类vo list
private List<SubCategoryVO> subCatList;
// getter & setter
}
<resultMap id="myCategoryVO" type="com.imooc.pojo.vo.CategoryVO">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="type" property="type"/>
<result column="fatherId" property="fatherId"/>
<!--
collection 标签:用于定义关联的list集合类型的封装规则
property:对应三级分类的list属性名
ofType:集合的类型,三级分类的vo
-->
<collection property="subCatList" ofType="com.imooc.pojo.vo.SubCategoryVO">
<id column="subId" property="subId"/>
<result column="subName" property="subName"/>
<result column="subType" property="subType"/>
<result column="subFatherId" property="subFatherId"/>
</collection>
</resultMap>
collection 的property属性要和VO中的 List类型的属性名称一致,否则会报题目所示错误。