zoukankan      html  css  js  c++  java
  • mybatis延迟加载

      当需要的时候到数据库中查询,

      1)首先在总配置文件中加

      <settings>

         <!-- 启用延迟加载  -->

        <setting name="lazyLoadingEnabled" value="true"/>

        <setting name="aggressiveLazyLoading" value="false"/>

      </settings>

       2) 在相应的配置文件中 

     <resultMap type="userbean" id="many2oneMap"

            <id column="uuid" property="userid"/>

            <result column="username" property="username"/>

            <association property="dep" javaType="cn.hd.po.Dept" column="did" select="findDeptByDid">

               <id column="did" property="did"/>

               <result column="depname" property="dname"/>

            </association>

         </resultMap>

        <select id="findDeptByDid" resultType="dept" parameterType="int">

        select * from t_dept where did=#{did}

        </select>

        <select id="queryAll"  resultMap="many2oneMap" >

          select userid as uuid,username,did

          from t_user t1

        </select>

      优点:需要再到数据库中查询,所以某个角度来说是可以提高效率

      缺点:会产生N+1问题

        

  • 相关阅读:
    让一个不固定高度的div,保持垂直水平居中的方法
    Set、Map、WeakSet 和 WeakMap
    JS 中常用的 Math 方法
    不使用 new,创建一个实例对象
    做一个弹窗
    变量提升
    事件委托实践
    vue组件通信
    新版vue脚手架关闭eslint
    图片懒加载原生js实现
  • 原文地址:https://www.cnblogs.com/joyous-day/p/6137681.html
Copyright © 2011-2022 走看看