MyBatis(延迟加载 缓存)

Mybatis一级缓存二级缓存 延迟加载 Mybatis 一级缓存 二级缓存 延迟加载 你了解多少??? 阅读详情

mybatis目录

一对一延迟加载
1.在SqlMapConfig.xml中配置setting标签
2.在IAccoutDao.xml中配置association标签
3.测试类
4.成功运行
一对多延迟加载
2.在IUserDao.xml中配置collection标签
缓存
一级缓存
二级缓存
1.SqlMaoConfig.xml中
2.在需要使用二级缓存的实体类的mapper中
3.测试类

一对一延迟加载

1.在SqlMapConfig.xml中配置setting标签

详情看中文官网

<settings>
        <!-- 配置全局缓存-->
        <setting name="lazyLoadingEnabled" value="true"/>

        <setting name="aggressiveLazyLoading" value="true"/>
    </settings>
2.在IAccoutDao.xml中配置association标签
<!--定义封装account和user的resultMap-->
    <resultMap id="accountUserMap" type="Account">
        <id property="id" column="id"></id>

        <result property="uid" column="uid"></result>
        <result property="money" column="money"></result>

        <!--一对一的关系映射,配置封装user的内容
        select属性的内容,查询用户的唯一标识符
        column属性的内容:用户根据id查询时,所需要参数的值-->
        <association property="user" column="uid" javaType="User" select="com.daniel.dao.IUserDao.findById">
            <id property="id" column="id"></id>
            <result property="username" column="username"></result>
            <result property="sex" column="sex"></result>
            <result property="address" column="address"></result>
            <result property="birthday" column="birthday"></result>
        </association>
    </resultMap>

    <select id="findAll" resultMap="accountUserMap">
        select * from  account
    </select>
3.测试类
@Test
    public void findAll(){
        List<Account> accounts = accoutDao.findAll();
        for (Account account:
             accounts) {
            System.out.println("每一个account的信息");
            System.out.println(account);
            System.out.println(account.getUser());
        }
    }
4.成功结果

在这里插入图片描述

一对多延迟加载

和一对一没有太多区别

2.在IUserDao.xml中配置collection标签
<!--定义封装account和user的resultMap-->
    <resultMap id="accountUserMap" type="Account">
         <id property="id" column="id"></id>
        <result property="username" column="username"></result>
        <result property="sex" column="sex"></result>
        <result property="address" column="address"></result>
        <result property="birthday" column="birthday"></result>

        <!--一对一的关系映射,配置封装user的内容
        select属性的内容,查询用户的唯一标识符
        column属性的内容:用户根据id查询时,所需要参数的值-->
    	<collection property="accounts" ofType="Account" select="com.daniel.dao.IAccoutDao.findAccountByUid" column="id">
            <id property="id" column="aid"></id>
            <result property="uid" column="uid"></result>
            <result property="money" column="money"></result>
        </collection>
    </resultMap>

缓存

在这里插入图片描述

一级缓存

其实mybatis中默认就是一级缓存了(平时的测试类就是一级缓存存在SqlSession中)

二级缓存

1.SqlMaoConfig.xml中
<settings>
        <setting name="cacheEnabled" value="true"/>
    </settings>
2.在需要使用二级缓存的实体类的mapper中
<!--开启user支持二级缓存-->
    <cache/>

 <!-- 根据id查询用户   注意属性useCache -->
    <select id="findById" parameterType="INT" resultType="user" useCache="true">
        select * from user where id = #{uid}
    </select>
3.测试类
public class SecondLevelCacheTest {

    private InputStream in;
    private  SqlSessionFactory factory;

    @Before//用于在测试方法执行之前执行
    public void init()throws Exception{
        //1.读取配置文件,生成字节输入流
        in = Resources.getResourceAsStream("SqlMapConfig.xml");
        //2.获取SqlSessionFactory
        factory = new SqlSessionFactoryBuilder().build(in);

    }

    @After//用于在测试方法执行之后执行
    public void destroy()throws Exception{
        in.close();
    }

    /**
     * 测试二级缓存
     */
    @Test
    public void testFirstLevelCache(){
        SqlSession sqlSession1 = factory.openSession();
        IUserDao dao1 = sqlSession1.getMapper(IUserDao.class);
        User user1 = dao1.findById(41);
        System.out.println(user1);
        sqlSession1.close();//一级缓存消失

        SqlSession sqlSession2 = factory.openSession();
        IUserDao dao2 = sqlSession2.getMapper(IUserDao.class);
        User user2 = dao2.findById(41);
        System.out.println(user2);
        sqlSession2.close();

        System.out.println(user1 == user2);
    }


}

在这里插入图片描述
注意:
从图中可以看出来第二次findbyId根本没有走数据库(数据都是从SqlSessionFactory的二级缓存中拿的 不是对象!)

mybatis教程5(延迟加载和缓存) 关联关系 在关系型数据库中,表与表之间很少是独立与其他表没关系的。所以在实际开发过程中我们会碰到很多复杂的关联关系。在此我们来分析下载mybatis中怎么处理这些关系 1对1关系 我们有一张员工表(T_EMP),一张部门表(T_DEPT)。员工表中的一条记录对应于部门表中有且仅有一条记录。这就是一对一的关联关系。 查询每个员工的信息及对应的部门信息 对象与对象1对1 部门对象: // 部... 阅读详情

相关推荐

用户消费行为分析(MapReduce实现,Hive分析)

一、题目要求 数据来自CDNow网站的一份用户购买CD明细,本数据集共有 6 万条 左右数据,数据为 CDNow 网站 1997年1月至1998年6月的用户行为 数据

紫烟的博客 3014

Java框架-mybatis延迟加载、缓存和注解开发

1. 延迟加载 1.1 概念 在需要用到数据时才进行加载,不需要用到数据时就不加载数据。也称作懒加载 好处:先从单表查询,需要时再从关联表去关联查询,大大提高数据库性能 缺点:在大批量数据查询时,由于查询会耗时,可能导致用户等待时间变长,影响用户体验 其中:mybatis的association、collection标签具备延迟加载功能 及时加载:一次加载所有数据。 1.2 一对一实现延时加载...

KeepStruggling的博客 827

MOSS-TTS开源语音合成家族:从架构解析到生产部署实战

语音合成(TTS)技术旨在让计算机将文本转换为自然流畅的语音,其核心原理通常涉及文本分析、声学模型和声码器等模块。近年来,基于深度学习的端到端TTS模型,特别是结合残差向量量化(RVQ)和Transformer架构的方案,显著提升了合成语音的自然度和效率。这类技术的价值在于能够广泛应用于有声内容创作、智能助手、无障碍服务以及实时交互等场景。本文聚焦于开源的MOSS-TTS家族,它通过模块化设计,针对高保真合成、多角色对话、实时交互等不同需求提供了专用模型。文章深入解析了其底层的Delay与Local两种架构

weixin_28745565的博客 422

springmvc 集成 mybatis 使用懒加载后,返回JSON报错

参考资料:http://m.blog.youkuaiyun.com/article/details?id=51236938 解决方案 为SpringMVC里默认序列化使用的 com.fasterxml.jackson.databind.ObjectMapper 设置其属性 SerializationFeature.F AIL_ON_EMPTY_BEANS 为fal

justinytsoft的博客 6705

信捷CODESYS平台伺服电机转矩控制模式应用与切换

信捷CODESYS二次开发软件:XS Studio 在运动控制中的转矩控制案例

weixin_64614866的博客 1万+

卫星测试科普(三):卫星载荷的核心测试设备探秘

总的说来,卫星芯片与元器件,部组件与单机,整机与子系统,系统与整星的设计、定型、制造、验证、总装、发射、在轨等环节都离不开各种测试场景,对于这些卫星测试场景而言,“射频三大件”与高速数字示波器是构成强大测试系统的基础。卫星通信信号生成:覆盖Ka、Q等波段,具备扫频、脉冲、数字调制、噪声信号、雷达信号、数据链信号、OFDM 等多种信号库,用于测试和验证卫星电子设备的电气性能、频率响应、抗干扰能力等。卫星的通信需要高效、快速地传输大量数据,高速信号的质量至关重要,如果卫星信号不佳,卫星就会出现故障或者隐患。

spwbjss的博客 2320

Mybatis懒加载导致Json序列化问题

Mybatis懒加载导致Json序列化问题 问题现场: 使用Mybatis, <collection> 标签, 查一个实体类,和其子List. 报错 [simple type, class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProx...

creaylei的小花园 1365

【unity游戏开发之InputSystem——01】通过写代码监听InputSystem输入(基于unity6开发介绍)

通过写代码监听InputSystem输入(基于unity6开发介绍)

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 4893

mybatis延迟加载原理解析

MyBatis延迟加载机制解析 本文详细分析了MyBatis的延迟加载实现原理。延迟加载通过在需要时才执行查询来提升性能,避免不必要的数据库操作。MyBatis通过动态代理(默认使用Javassist)实现延迟加载,主要流程包括: 配置开启延迟加载功能 ResultMap中使用association/collection标签配置延迟加载属性 查询时创建代理对象并维护延迟加载信息 访问属性时触发代理逻辑执行实际查询 ResultLoader完成数据加载并赋值 核心在于ResultLoaderMap和Resul

m0_49516995的博客 1493

基于Simulink的四足机器人关节力矩优化仿真建模示例

高自由度:每个腿至少有3个自由度(DOF),增加了控制的复杂性。非线性动力学:涉及多体系统的相互作用,包括接触力、摩擦力等。能量消耗:减少不必要的能量消耗是提升续航能力和效率的关键。可以是最小化能量消耗或最大化稳定性等。matlab深色版本% 示例代码通过本指南,我们介绍了如何基于Simulink搭建一个四足机器人的关节力矩优化模型,并进行了仿真以验证其基本功能。

amy_mhd的博客 172

[ vulhub漏洞复现篇 ] Django SQL注入漏洞复现 CVE-2021-35042

[ vulhub漏洞复现篇 ] Django SQL注入漏洞复现 CVE-2021-35042 Django 组件存在 SQL 注入漏洞,该漏洞是由于对 QuerySet.order_by()中用户提供数据的过滤不足,攻击者可利用该漏洞在未授权的情况下,构造恶意数据执行 SQL 注入攻击,最终造成服务器敏感信息泄露。

qq_51577576的博客 3229

MyBatis延迟加载及缓存

MyBatis延迟加载与缓存机制详解 摘要: MyBatis提供延迟加载功能优化数据访问性能,通过代理对象实现按需加载关联数据,减少初始加载时间和内存消耗。配置需在mybatis-config.xml中开启lazyLoadingEnabled,通过fetchType指定关联关系加载策略。同时MyBatis具备两级缓存机制:一级缓存为SqlSession级别,默认开启;二级缓存为Mapper级别,需显式配置,可跨SqlSession共享。缓存机制通过减少数据库访问提升性能,但需注意N+1问题和缓存一致性。实体

qq_21262107的博客 1677

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

mybatis延迟加载、缓存

延迟加载:当前查询用户的时候,没有把该用户所拥有的账户信息查询出来,而是使用账户数据的时候,再去查询账户的数据。②查询的时候,先从SqlSession的缓存中查找,如果有,直接返回,如果没有,再去查询数据库。可以看出,sql语句只执行了一次,说明它是查的缓存,但是地址不一样,因为他从缓存里组装出来的。二级缓存的适用对象地址不同,但是也从缓存加载,二级缓存存储的是零散数据,是组装出来的对象。(2)查询用户的时候,可以先不查账户信息,需要账户信息的时候再去查,这时选择延迟加载。

2201_76081438的博客 1465

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

mybatis延迟加载和缓存

一、mybatis延迟加载 1、延迟加载概述 (1)延迟加载又叫懒加载,也叫按需加载。也就是说先加载主信息,在需要的时候,再去加载从信息 (2)在mybatis中,resultMap标签 的association标签和collection标签具有延迟加载的功能。 2、延迟加载案例分析 (1)需求:查询订单信息,关联查询用户信息 a、创建一个statement来查询订单信息 b...

shaonianbz的博客 945

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

MyBatis延迟加载和缓存

本文主要介绍了MyBatis框架中的延迟加载策略和缓存机制。延迟加载分为立即加载和延迟加载,立即加载在查询时同时加载关联数据,而延迟加载则在需要时才加载关联数据。文章通过一对多和多对一的查询场景,详细演示了如何配置和使用延迟加载。此外,文章还介绍了MyBatis的缓存机制,包括一级缓存和二级缓存。一级缓存是SqlSession级别的缓存,生命周期与SqlSession相同;二级缓存是跨SqlSession的缓存,需要在配置文件中开启,并且实体类需要实现序列化接口。通过测试代码,文章展示了如何验证一级缓存和二

qq_73993301的博客 637

mybatis的延迟加载&缓存

mybatis的延迟加载&缓存 一、延迟加载:在需要用到数据时才进行加载,不需要用到数据时就不加载数据。延迟加载也称懒加载. 好处:先从单表查询,需要时再从关联表去关联查询,大大提高数据库性能,因为查询单表要比关联查询多张表速度要快。 assocation 实现延迟加载 1. **账户的持久层 DAO 接口** :List<Account> findAll(); 2...

weixin_38255444的博客 180

MyBatis 延迟加载与缓存

技术核心作用关键配置延迟加载减少初始查询数据量,提升响应速度的select属性一级缓存减少同一会话内的重复查询自动生效,无需额外配置(注意SqlSession生命周期)二级缓存跨会话共享缓存,减少数据库压力实体类序列化、<cache/>标签、缓存策略配置合理运用延迟加载和缓存,能显著提升 MyBatis 应用的性能,但需根据业务场景灵活选择,避免过度使用导致数据不一致或内存溢出。

2301_77071977的博客 981

Mybatis的延迟加载&&缓存

Mybatis的延迟加载&&缓存 1. Mybatis中的延迟加载 延迟加载问题引入 问题:在一对多中,当我们有一个用户,他有100个账户。 1. 在查询用户的时候,要不要把关联的账户查询出来。 2. 在查询账户的时候,要不要把关联的用户查询出来。 答案: 1. 在查询用户的时候,用户下关联的账户信息应该是:什么时候使用,什么时候查询出来的。 2. 在查询账户的时候,账户下所属的用户信息应该是随着账户查询时一起查询出来的。 延迟加载和立即加载 1. 延迟加载:在真正使用数据

Eternal_Summer 196

Mybatis的缓存机制和延迟加载

上一篇部分阅读了Mybatis的源码梳理了一下它作为ORM层解决方案是如何帮助我们访问数据库的,今天想再总结一下Mybatis的两个特性。 Mybatis缓存机制分为一级缓存和二级缓存。 一级缓存是sqlSession级的,即利用同一个sqlSession执行查询相同的SQL,数据会直接从缓存中取。我们都知道一个sqlSession会对应new一个调度器Excutor对象,每次Excutor去...

白白胖胖充满希望 454

MyBatis-延迟加载与MyBatis缓存(面试题)

MyBatis-延迟加载与MyBatis缓存-概念性 MyBatis-延迟加载与MyBatis缓存MyBatis-延迟加载与MyBatis缓存-概念性延迟加载(面试题)1、什么是延迟加载(按需加载)2、延迟加载MyBatis缓存(面试题)1、Cache缓存2、MyBatis缓存分析3、一级缓存4、二级缓存原理开启二级缓存5、禁用二级缓存6、刷新二级缓存 延迟加载(面试题) 1、什么是延迟加载(按需...

Dokikilililiya 3714

mybatis之延迟加载和缓存

mybatis之延迟加载和缓存关联关系1对1关系1对多关系多对多关系延迟加载开启延迟加载一对一一对多缓存缓存分类一级缓存二级缓存 关联关系 在关系型数据中,表与表之间很少是独立与其他表没关系的。所以在实际开发中我们会碰到很多复杂的关联关系。在此我们来分析下mybatis中怎么处理这些关系。 1对1关系 我们有一张员工表 t_emp 和一张一张部门表 t_dept。员工表中的一条记录对应于部门表中有...

Ariqiao的博客 250

MyBatis学习总结(四) MyBatis 延迟加载策略MyBatis 一级缓存、二级缓存MyBatis注解开发

延迟加载:就是在需要用到数据时才进行加载,不需要用到数据时就不加载数据。延迟加载也称懒加载。好处:先从单表查询,需要时再从关联表去关联查询,大大提高数据库性能,因为查询单表要比关联查询多张表速度要快。坏处:因为只有当需要用到数据时,才会进行数据库查询,这样在大批量数据查询时,因为查询工作也要消耗时间,所以可能造成用户等待时间变长,造成用户体验下降。一对一,多对一:通常情况下我们都是采用立即加载。一对多,多对多:通常情况下我们都是采用延迟加载。

long3359的博客 667
上一篇: MyBatis第四天(多表查询)
下一篇: mybatis使用注解开发
JSON_ZJS
博客等级 码龄9年 30粉丝 159原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值