一对多映射
属性名resultList 类型为List集合 该集合是根据UserObj的t_id进行ResultObj查询
column是本表要传入的select语句块中的参数,集合查询的定义为resultByUid
<association property="resultList" column="t_id"select="
resultByUid"/>
查询
<select id="resultByUid" resultMap="resultData">
select* from t_result where uid=#{uid}
</select>
添加
<insertid="addResult" parameterType="results">
insert into t_result(pointer,userId) values(#{pointer},#{user.id});
</insert>
根据id查询,返回一个查询结果
<resultMapclass="teacher" id="
tm">
<association property="studentList"column="id" select="
findStudentByTeacher"/>
</resultMap>
<selectid="findTeacher" resultMap="
tm">
select * from t_teacher where id=#{id};
</select>
联接中间表按老师查询学生集合
<select id="
findStudentByTeacher"resultType="student">
SELECT s.* FROM t_student s JOIN t_teacher_student ts ON s.id=ts.studentId WHEREts.teacherId=#{id};
</select>
循环添加中间表记录
<insertid="addcenter">
insert into t_teacher_student(teacherId,studentId) values
<foreach collection="students" separator=","item="studentId">
(#{id},#{studentId})
</foreach>
</insert>
持久层缓存的范围
1、事物级缓存
一级缓存,当session建立时缓存,session关闭时结束
2、应用级缓存
二级缓存,当应用开启时缓存,应用结束缓存结束 ,存在并发访问缓存