为了解决属性名和字段名不相同的问题
example:MyBatis-CRUD: Mybatis做增删改查
使用resultmap前查询password时为空,因为属性名与字段名不相同

做结果集映射:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.heerlin.dao.UserDao">
<!--结果集映射-->
<resultMap id="UserMap" type="User">
<!--    column数据库中的字段,property实体类中的属性-->
    <result column="id" property="id"/>
    <result column="name" property="name"/>
    <result column="pwd" property="password"/>
</resultMap>
<!--    根据id去查用户-->
    <select id="getUserById" resultMap="UserMap">
        select * from mybatis.user where id=#{id};
    </select>
</mapper>结果:

官网:上述语句只是简单地将所有的列映射到 HashMap 的键上,这由 resultType 属性指定。虽然在大部分情况下都够用,但是 HashMap 并不是一个很好的领域模型。你的程序更可能会使用 JavaBean 或 POJO(Plain Old Java Objects,普通老式 Java 对象)作为领域模型。MyBatis 对两者都提供了支持。 
















![[回馈]ASP.NET Core MVC开发实战之商城系统(二)](https://img-blog.csdnimg.cn/img_convert/46ea527c059d8e3a208bbe2d58a84c9d.png)


