zoukankan      html  css  js  c++  java
  • 一对多,多对一,自关联,多对多,一级缓存,二级缓存

    一对多   Dad------>Son
           
           两种方案:单条SQL

                       <resultMap id="DadMapper" type="Dad">
                  <id property="fatherid" column="fatherid"></id>
                  <collection property="sons" ofType="Son">
                        <id property="sonid" column="sonid"></id>
                    <result property="sonname" column="sonname"/>
                  </collection>
               </resultMap>
                       <select resultMap="DadMapper">
                 select sonname,fathername from son,dad where son.fatherid=dad.fatherid
                 and dad.fatherid=#{fatherid}
               </select>
                   
                     多条SQL
       多对一:两种方案:单条SQL
                     多条SQL
       自关联:无限级菜单
               DB表结构
           Category表名
           cid  cname      pid
            1    服装       0
            2    儿童服装   1
            3    儿童男装   2

            xml 思想递归  
            :使用的是一对多  一个分类关联一个分类集合。
         <resultMap id="CategoryMapper" type="Category">
            <id column="cid" property="cid"></id>
            <result column="cname" property="cname"></result>
            <collection property="cates" ofType="Category" select="getChildrenListByPid" column="cid">
            </collection>
            </resultMap>
             <!--查询-->
            <select id="getChildrenListByPid" resultMap="CategoryMapper">
            select * from category where pid=#{pid}
            </select>
        dao层:
            List<Category> List<List<List<Category>>>


       多对多:老师和学生

      一级缓存:MyBatis中一级默认是内置的,一级缓存不能卸载。

       缓存目的不是为了共享查询结果 。sqlid+select * from dept

      二级缓存的属性
      eviction:缓存中保存对象的清理策略
         FIFO:First in first out 先进先出
          数据结构:队列
          栈:先进后出
         LRU:least Recently used 最近最少使用的对象
         flushInterval:刷新间隔

     1.MyBatis中二级缓存默认是开启的吗?
       解析:是的 setttings cacheEnabled true
             3个条件
            1.开启二级缓存
            2.<cache/> 小配置
            3.标识接口 Serialiazable
          
          <cache
            eviction="FIFO"
             flushInterval="60000"
             size
             readOnly
          />

  • 相关阅读:
    距离计算方法总结 转自http://www.cnblogs.com/xbinworld/archive/2012/09/24/2700572.html#2663469
    2014.11.20查看到的有用网站和资料
    转载的计算机视觉方面的牛人博客,出处:blog.csdn.net/carson2005
    Java spring boot 2.0连接mysql异常:The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
    Spring 复习第一天
    mysql 5.6.43免安装版安装教程
    JVM内存限制(最大值)
    修改电脑的ip
    Oracle 维护
    Oracle 操作
  • 原文地址:https://www.cnblogs.com/yfyfyff/p/7665715.html
Copyright © 2011-2022 走看看