resultMap 元素是 MyBatis 中最重要最强大的元素。方式1:对sql中某个字段在操作的时候起别名,来跟类的属性名一致
方式2:resultMap,将类属性映射到表字段
<!--结果集映射-->
<resultMap id="userMap" type="user">
<!--property类属性,column表字段-->
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="pwd" column="pwd"/>
</resultMap>
<select id="selectUserById" resultMap="userMap">
select * from user where id = #{id}
</select>
ResultMap 的优秀之处——你完全可以不用显式地配置它们,即类属性和表字段名一致的不需要显示定义
<resultMap id="userMap" type="user">
<!--property类属性,column表字段-->
<result property="pwd" column="pwds"/>
</resultMap>
这只是单表查询的情况,多表查询1:n/n:m情况就是另一种情况。