Mybatis resultType resultMap 区别
MyBatis
每一个查询映射的返回类型都是ResultMap
,只是当我们提供的返回类型属性是resultType
的时候,MyBatis
会自动的把对应的值赋给resultType
所指定对象的属性。- 当我们提供的返回类型是
resultMap
的时候,将数据库中列数据复制到对象的相应属性上,两者不能同时使用。
resultType
:<select id="selectUser" parameterType="int" resultType="User">
select * from user where id = #{id}
</select>
resultMap
:<!-- column:数据库中列名称,property:类中属性名称 -->
<resultMap type="User" id="userMap">
<id column="id" property="id"/>
<result column="name" property="name"/>
</resultMap>
<select id="selectUserList" resultMap="userMap" >
select * from user
</select>
还没有评论,来说两句吧...