• 一对多,多对一,自关联,多对多,一级缓存,二级缓存


    一对多   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
          />

  • 相关阅读:
    原来这样就可以开发出一个百万量级的Android相机
    微信读书这样排版,看过的人都很难忘!
    AI小白快上车!这是发往高薪职位的车!
    短视频APP是如何开启你的美好生活的?
    自从我这样撸代码以后,公司网页的浏览量提高了107%!
    如果想成为一名顶尖的前端,这份书单你一定要收藏!
    老板今天问我为什么公司的数据库这么烂,我是这样回答的......
    MapReduce Notes
    HDFS Architecture Notes
    BloomFilter
  • 原文地址:https://www.cnblogs.com/yfyfyff/p/7665715.html
Copyright © 2020-2023  润新知