Mybatis Ambiguous collection type for property ‘xxx‘. You must specify ‘java Type‘ or ‘resultMap‘.

2022-07-28,,,,

使用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类型的属性名称一致,否则会报题目所示错误。

本文地址:https://blog.csdn.net/qq_43581949/article/details/109616975

《Mybatis Ambiguous collection type for property ‘xxx‘. You must specify ‘java Type‘ or ‘resultMap‘..doc》

下载本文的Word格式文档,以方便收藏与打印。