Result Maps collection does not contain value for

MyBatis报这个错的原因

1. BaseResultMap 的问题

<resultMap id="UserMap" type="com.test.User">
  ...
</resultMap >
<select id="selectUser" resultMap="UserMaper">
  ...
</select>

resultMap标签 的id 是 UserMap 而select 的resultMap要和上边的 id 属性值统一名字

2. <resultMap> 标签里面的字段和 type属性实体类的对不上,不管是少了还是类型对不上之类的,解决办法就是检查字段映射

3.用resultMap返回其他类型

<select id="selectUser" resultMap="com.ssm.study.entity.User"> 
  ...
</select>
<select id="selectUser" resultType="com.ssm.study.entity.User">
  ...
</select>

第一个会报错、第二个是正确的

就是把resultMap和resultType搞混了 ,resultMap只能返回实体映射<resultMap>

返回其他类型 如:com.ssm.study.entity.User 就使用 resultType

 

posted @ 2021-12-16 17:42  小※兽  阅读(348)  评论(0编辑  收藏  举报