<resultMapid="map"type="com.example.demo.entity.PlayTotal"><idcolumn="id"jdbcType="INTEGER"property="id"/><resultcolumn="name"jdbcType="VARCHAR"property="name"/><!--1.直接手写--><associationproperty="studentList"javaType="com.example.demo.entity.Student"><idcolumn="b_id"jdbcType="INTEGER"property="id"/><resultcolumn="b_name"jdbcType="VARCHAR"property="name"/><resultcolumn="b_user_id"jdbcType="INTEGER"property="userId"/></association><!--2.前缀手写--><associationproperty="studentList"columnPrefix="b_"javaType="com.example.demo.entity.Student"><idcolumn="id"jdbcType="INTEGER"property="id"/><resultcolumn="name"jdbcType="VARCHAR"property="name"/><resultcolumn="user_id"jdbcType="INTEGER"property="userId"/></association><!--3.前缀并且其他地方引入--><associationproperty="studentList"columnPrefix="b_"resultMap="com.example.demo.dao.StudentBaseDao.BaseResultMap"></association></resultMap><selectid="select"resultMap="map">
select a.id, a.name,
b.id as b_id, b.name as b_name,
b.user_id as b_user_id
from play a
inner join student b
on a.id = b.user_id
</select>
一对多(基本数据类型)
<resultMapid="map"type="com.example.demo.entity.PlayTotal"><idcolumn="id"jdbcType="INTEGER"property="id"/><resultcolumn="name"jdbcType="VARCHAR"property="name"/><collectionproperty="studentList"ofType="java.lang.String"><constructor><argcolumn="b_name"/></constructor></collection></resultMap><selectid="select"resultMap="map">
select a.id, a.name,
b.name as b_name
from play a
left join student b
on a.id = b.user_id
</select>
一对多
<resultMapid="map"type="com.example.demo.entity.PlayTotal"><idcolumn="id"jdbcType="INTEGER"property="id"/><resultcolumn="name"jdbcType="VARCHAR"property="name"/><!--2.前缀手写--><collectionproperty="studentList"columnPrefix="b_"ofType="com.example.demo.entity.Student"><idcolumn="id"jdbcType="INTEGER"property="id"/><resultcolumn="name"jdbcType="VARCHAR"property="name"/><resultcolumn="user_id"jdbcType="INTEGER"property="userId"/></collection><!--3.前缀其他地方引入--><collectionproperty="studentList"columnPrefix="b_"resultMap="com.example.demo.dao.StudentBaseDao.BaseResultMap"></collection></resultMap><selectid="select"resultMap="map">
select a.id, a.name,
b.id as b_id, b.name as b_name,
b.user_id as b_user_id
from play a
left join student b
on a.id = b.user_id
</select>