很简单,就比如说咱们查询一个一对多的表,比如有个学生表,和关联家长表,学生表有个字段是家长信息。每个学生的家长信息用集合来存储。这样就构造了一个场景。
student表
id 主键 varchar
name varchar
parentlist list
关联家长表
id 主键 varchar
student_id 外键 varchar
parentname varchar
phone varchar
创建一个vo用来返回连表查询的数据字段,接着写sql语句,
<resultMap id="jiazhang" type="com.xxx.xxx">
<result column="id" property="id"/>
<result column="student_id" property="studentId"/>
<result column="parentname " property="parentname "/>
<result column="phone " property="phone"/>
</resultMap>
<resultMap id="student"
type="com.xxxx.xxx">
<result column="id" property="id"/>
<result column="name" property="name"/>
<association property="parentlist " resultMap="jiazhang"/>
</resultMap>
<select id="selectListByTime"
resultMap="student"
parameterType="java.util.HashMap">
SELECT
*
FROM
student s
LEFT JOIN persion p ON s.id = p.student_id
WHERE
1=1
<if test="startTime != null and startTime != '' and stopTime != null and stopTime != ''">
AND s.CREATE_TIME BETWEEN #{startTime} and #{stopTime};
</if>
</select>
就这些吧,因为这些代码是直接在csdn输入,可能有点问题,理解意思就好。不要较真