Exception in thread “main” org.apache.ibatis.builder.IncompleteElementException: Could not find result map ‘com.dao.PersonDao.cardAndPerson2’ referenced from ‘com.dao.PersonDao.selectPersonById2’
Bug意思是:
找不到从’com.dao.persondao.selectPersonByID2’引用的结果映射’com.dao.persondao.cardandPerson2’*(简单说:找不到cardandPerson2)
先找到对应的代码块:
<!-- 一对一根据id查询个人信息:级联查询的第二种方法(嵌套结构,执行一个SQL语句) -->
<resultMap type="com.po.Person" id="carAndPerson2">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<!-- 一对一级联查询 -->
<association property="card" javaType="com.po.Idcard">
<id property="id" column="idcard_id"/>
<result property="code" column="code"/>
</association>
</resultMap>
<select id="selectPersonById2" parameterType="Integer" resultMap="cardAndPerson2">
select p.*,ic.code
from [person] p,[idcard] ic
where p.idcard_id=ic.id and p.id=#{id}
</select>
原因:拼写不正确
解决办法:将id值改为cardAndPerson2,id与resultMap值保持一致,编译成功!