在sqlMapConfig中进行设置

<configuration>
<settings>
<!--延迟加载的总开关-->
<setting name="lazyLoadingEnabled" value="true"/>
<!--设置为false才是启动延迟加载-->
<setting name="aggresiveLazyLoading" value="false"/>
</settings>
......
</configuration>

在mapper.xml中使用两次查询的方式;

 <!-- 2.查询两次select * from class where c_id = 1 ; SELECT * from teacher where
t_id = 1 --> <select id="getClass2" resultMap="getClass2Map">
select * from class where c_id
=#{id}
</select>
<select id="getTeacher" parameterType="int" resultType="com.stone.bean.Teacher">
select
t_id id,t_name name
from teacher where t_id=#{id}
</select>
<select id="getStudents" parameterType="int" resultType="com.stone.bean.Student">
select
S_id id,s_name name from student where c_id=#{id}
</select>
<resultMap type="com.stone.bean.ClassT" id="getClass2Map">
<id property="id" column="c_id" />
<result property="name" column="c_name" />
<association property="teacher" column="t_id" select="getTeacher">
</association>
<collection property="list" column="c_id" select="getStudents"></collection>
</resultMap>

MyBatis 延迟加载的更多相关文章

  1. mybatis源代码分析:mybatis延迟加载机制改进

    在上一篇博客<mybatis源代码分析:深入了解mybatis延迟加载机制>讲诉了mybatis延迟加载的具体机制及实现原理. 可以看出,如果查询结果对象中有一个属性是需要延迟加载的,那整 ...

  2. mybatis源代码分析:深入了解mybatis延迟加载机制

    下文从mybatis(3.2.7)延迟加载样例讲起,逐步深入其实现机制. 下面的例子是Student类关联一个Teacher对象,在访问Student对象时,不立即加载其关联的Teacher对象,而是 ...

  3. 【MyBatis】MyBatis 延迟加载策略

    MyBatis 延迟加载策略 文章源码 什么是延迟加载 延迟加载,就是在需要用到数据时才进行加载,不需要用到数据时就不加载数据,也被成为懒加载. 好处:先从单表查询,需要时再从关联表去关联查询,大大提 ...

  4. MyBatis 延迟加载,一级缓存,二级缓存设置

    什么是延迟加载 resultMap中的association和collection标签具有延迟加载的功能. 延迟加载的意思是说,在关联查询时,利用延迟加载,先加载主信息.使用关联信息时再去加载关联信息 ...

  5. mybatis——延迟加载

    ------------------------------------------------SqlMapConfig.xml------------------------------------ ...

  6. mybatis延迟加载

    配置完成后可能会报错Cannot enable lazy loading because CGLIB is not available. Add CGLIB to your classpath 是由于 ...

  7. Mybatis学习记录(七)----Mybatis延迟加载

    1.什么是延迟加载 resultMap可以实现高级映射(使用association.collection实现一对一及一对多映射),association.collection具备延迟加载功能. 需求: ...

  8. Spring+SpringMVC+MyBatis深入学习及搭建(七)——MyBatis延迟加载

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/6953005.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(六)——My ...

  9. mybatis延迟加载一对多

    1.实体类 package cn.bdqn.bean; import java.util.Set; /** *国家的实体类 */ public class Country { private Inte ...

  10. Mybatis延迟加载和查询缓存

    摘录自:http://www.linuxidc.com/Linux/2016-07/133593.htm 阅读目录 一.延迟加载 二.查询缓存 一.延迟加载 resultMap可以实现高级映射(使用a ...

随机推荐

  1. PAT (Advanced Level) 1030. Travel Plan (30)

    先处理出最短路上的边.变成一个DAG,然后在DAG上进行DFS. #include<iostream> #include<cstring> #include<cmath& ...

  2. webapp之路--之query media

    query media是css3中的模块,对于移动端的开发是非常重要的,是响应式web设计的中不可或缺的一部分.简单点说就是根据不同移动设备的屏幕参数来制定不同的css方案以实现web的响应式开发.目 ...

  3. head和tail命令-----得到头尾N行或者这去掉尾头N/N-1行

    [algo@localhost tmp]$ cat test  1 2 3 4 5 head得到头部2行,删掉尾部2行 [algo@localhost tmp]$ head -n +2 test  1 ...

  4. Cannot call sendError() after the response has been committed - baiyangliu - 博客频道 - CSDN.NET

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  5. javascript模拟鼠标双击事件

    通常我们在做开发的时候需要通过单击切换对立事件,简单做了一个模型. <!DOCTYPE html> <html> <head> <title>javas ...

  6. [Lua]Lua入门教程

    什么是Lua Lua 是一个小巧的脚本语言.是巴西里约热内卢天主教大学(Pontifical Catholic University of Rio de Janeiro)里的一个研究小组,由Rober ...

  7. Instruments使用实战

    http://www.cocoachina.com/ios/20150225/11163.html 最近采用Instruments 来分析整个应用程序的性能.发现很多有意思的点,以及性能优化和一些分析 ...

  8. POJ 3458 Colour Sequence

    水题. #include<cstdio> #include<cstring> #include<cmath> + ; char s[maxn], v[maxn], ...

  9. 2017 ZSTU寒假排位赛 #2

    题目链接:https://vjudge.net/contest/147632#overview. A题,状态压缩一下然后暴力即可. B题,水题,略过. C题,有负数,前缀和不是单调的,因此不能用尺取法 ...

  10. mongodb学习(三) 安装和基本CRUD

    菜鸟啊...先吐槽一下自己 发现mongodb已经升级到2.6标准版了.  服务端最新安装方法: http://www.cnblogs.com/lzrabbit/p/3682510.html 一 准备 ...