JAVAEE学习笔记

一对多映射
属性名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、应用级缓存
二级缓存,当应用开启时缓存,应用结束缓存结束 ,存在并发访问缓存
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值