zoukankan      html  css  js  c++  java
  • Java_myBatis_XML代理_延迟加载

    使用mybatis的延迟加载,需要两个步骤:

    1.在全局配置文件中添加一下语句(lazyLoadingEnabled默认为false,aggressiveLazyLoading默认为true)

    <settings>
        <!-- 延迟加载总开关 -->
        <setting name="lazyLoadingEnabled" value="true"/>
        <!-- 侵入式延迟 -->
        <setting name="aggressiveLazyLoading" value="false"/>
    </settings>

    2.写好映射文件

    <resultMap type="User" id="CacheTest">
        <id column="id" property="id" />
        <result column="username" property="username" />
        <result column="birthday" property="birthday" />
        <result column="address" property="address" />
        <!-- column相当于传入parameter  ofType相当于resultType -->
        <collection property="orderList" column="id" ofType="Order"
            select="resultMap.resultMapMapper.CacheTestSelect">
            <result column="number" property="number" />
            <result column="createtime" property="createtime" />
        </collection>
    </resultMap>
    <select id="CacheTest" resultMap="CacheTest">
        select * from user
    </select>
    <select id="CacheTestSelect" parameterType="int" resultType="Order">
        select * from orders where user_id = #{id}
    </select>

    这样查询一开始会执行select * from user

    然后当读取到orderList时才会执行select * from orders where user_id = #{id}

  • 相关阅读:
    set
    网络流学习(最小费用最大流)
    网络流学习(最大流)
    模拟退火学习
    NOI Day1T1归程(Kruskal重构树+Dijkstra)
    线性基学习
    高斯消元学习
    manacher算法学习(求最长回文子串长度)
    AC自动机模板2
    AC自动机入门
  • 原文地址:https://www.cnblogs.com/amiezhang/p/9614946.html
Copyright © 2011-2022 走看看