实体类的属性、数据表的字段: 类型、名字不一致时(stuno,id)
注意:当属性名 和字段名不一致时,除了使用resultMap以外,还可以使用resultType+HashMap:
a. resultMap
使用resultMap将不一致属性与数据表一一对应
<resultMap type="student" id="queryStudentByIdMap">
<!-- 指定类中的属性 和 表中的字段 对应关系 -->
<id property="stuNo" column="id" />
<result property="stuName" column="name" />
</resultMap>
b.resultType+HashMap
select 表的字段名 “类的属性名”(取别名) from table_name 来制定字段名 和属性名的对应关系(系统会进行判断,例如表中字段id对应类中属性stuNo)
<select id="queryStudentByIdWithHashMap" parameterType="int" resultType="student" >
select id "stuNo",name "stuName" from student where id = #{id}
</select>
注意: 如果如果10个字段,但发现 某一个字段结果始终为SQL数据类型的默认值(例如:0、0.0、null等),则很可能是SQL语句中类的属性名写错。