<select id="employeeList" resultMap="employeeAndDepAndSkill"></select>
<!--resultMap元素自定义结果映射-->
<resultMap id="employeeAndDepAndSkill" type="com.spring.pojo.Employee">
<id property="id" column="id"/>
<result property="account" column="account"/>
<association property="department" javaType="com.spring.pojo.Department">
<id property="id" column="did"/>
<result property="dname" column="dname"/>
</association>
<collection property="skills" ofType="com.spring.pojo.Skill">
<id property="id" column="sid"/>
<result property="sname" column="sname"/>
</collection>
</resultMap>
select中的resultMap对应resultMap标签中的id
resultMap标签中的子元素id:指定与数据表中的主键字段对应的标识属性
resultMap标签中的子元素result:指定结果集字段与实体类中的属性的映射关系(即非主键)
property对应实体类中的名称,column对应数据表中的列名(如果使用的as设置别名,则为所设置的别名)
association元素:
用于处理“has-one”关系,即“一对一”’
association元素的property属性:实体类中用来映射结果子集的属性
association元素的javaType属性:用于指定property指定的属性的数据类型
collection元素:
用于处理“一对多”关系
collection元素的property属性:实体类中用来映射结果子集的属性
collection元素的ofType属性:用于指定property指定的集合属性中的元素的数据类型
注意:association元素包含的属性是javaType,而collection元素包含的属性是ofType