输出参数resultType
1.简单类型(8个基本类型+String)
2.输出参数为实体对象类型
3.输出参数为实体对象类型的集合,resultType依然需要写
4.输出类型为hashmap
–HashMap本身是一个集合,可以放多个元素,
但是提示发现,返回值为hashmap时,查询的结果只能是一个学生(stuno,stuname)
–>结论:一个hashmap对应一个学生的多个元素(多个属性)(一个map一个学生)
二维数组
{
{1,sd,45,wqd} *对应一个hashmap对象
{2,we,874,wqe}
{3,ef,751,wqw}
{4,gr,7521,wqc}
}
resultType
resultMap:实体类的属性,数据表的字段:类型,名字不同时
注意:当属性名与字段名不一致时,除了使用resultmap以外,还可以使用resultType+HashMap
a.resultMap
<select id="queryStudentById" parameterType="int" resultMap="queryStudentById">
select id,name from student where id=#{id}
</select>
<resultMap type="student" id="queryStudentById">
<!-- 指定类中的属性和表中的字段对应关系 -->
<id property="stuNo " column=" id"/>
<result property="stuName" column="name"/>
</resultMap>
b.resultType+HashMap
select 表的字段名 “类的属性名”from
<select id="queryStudentByIdWithHashMap" parameterType="int"
resultType="student">
select id "stuNo",name "stuName" from student where id=#{id}
</select>
如果发现输入的字段,有默认值(0 Or null),则可能字段名写错