org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.abc.beans.Minister

使用mybatis进行一对多嵌套查询时出错,错误原因:

    <select id="findMinisterById" resultMap="com.abc.beans.Minister">
      select mid,mname from minister where countryId = #{cid}
    </select>
    <resultMap id="AndSelectCountry" type="com.abc.beans.Country">
        <id property="id" column="cid"/>
        <result property="name" column="cname"/>
        <collection property="minister"
                    column="cid"
                    ofType="com.abc.beans.Minister"
                    select="findMinisterById">
        </collection>
    </resultMap>
    <select id="findById" resultMap="AndSelectCountry">
        select cid,cname from country where cid = #{id}
    </select>
</mapper>

java.lang.IllegalArgumentException: Result Maps collection does not contain value for xxxx.xxx
解决办法:
1.检查mybatis的xml配置
2.在某处肯定有配错了的,如"resultMap" -->“resultType”

像我这样的因为findMinisterById查询时,返回的是com.abc.beans.Minister类型,此时如果该实体类和对应的表属性值一致,就要把这个标红的resuitMap改为resultType

与其战胜敌人一万次,不如战胜自己一次。
原文地址:https://www.cnblogs.com/hyjh/p/11985150.html