一、简介:
resultMap 元素是 MyBatis 中最重要最强大的元素
ResultMap 的设计思想是,对简单的语句做到零配置(实体类属性名与数据库中的字段名不一致)
二、对于简单的resultMap的使用场景:
当我们的实体类属性名与数据库中的字段名不一致时,我们需要用到resultMap
三、解决方案:
方案1:我们可以通过配置resultMap【推荐】
引用它的语句中设置 resultMap 属性就行了(注意我们去掉了 resultType 属性)
<resultMap id="UserRes" type="User">
<result column="passwd" property="pwd"/>
</resultMap>
<!--条件查询-->
<select id="selUserByID" parameterType="int" resultMap="UserRes">
select * from `user` where id = #{int}
</select>
方案二:起别名
<select id="selUserByID" parameterType="int" resultType="stdpei.pojo.User">
select id ,name, passwd as pwd from `user` where id = #{int}
</select>