首页 > 编程语言 >Mybatis源码解读

Mybatis源码解读

时间:2023-02-06 12:31:52浏览次数:121  
标签:缓存 关键字 二级缓存 解读 mybatis sqlsession 源码 Mybatis 打开


1.mybatis4种加载配置文件的方式:

     (1)相对应类资源路径的引用,属性关键字resource:

          <mappers>
              <mapper resource="mapper/PostMapper.xml"/>
         <mappers>

    (2)相对应资源定位符,属性关键字url:
        <mappers>
            <mapper url=""file:///var/mappers/AuthorMapper.xml"/>
        <mappers>

    (3)使用接口类路径,属性关键字class:
       <mappers>
            <mapper class="org.mybatis.builder.AuthorMapper"/>
       <mappers>
    (4)使用扫描包的方式
      <mappers>
            <mapper name="com.xx.xxx"/>
      <mappers>

2.mybatis3种sql执行器
     simple
     reuse
     batch

3.mybatis的2级缓存
     mybatis的一级缓存是sqlsession级别的缓存,如果sqlsession打开,关闭或更新后,缓存即清空;
    mybatis的二级缓存是sqlsessionFactory级别的缓存,同一个sessionFactory打开的多个sqlsession共享同一个缓存; 
    一级缓存默认打开;二级缓存默认不会打开;
    缓存的读取顺序: 2级缓存>1级缓存>读取数据库;
    二级缓存的打开方式:

<setting name="cacheEnabled" value="true"/>
       配置某个xml支持缓存: <cache/>
       配置某个sql支持缓存:<select id="findById" resultType="com.xxx.object" parameterType="INT" useCache="true">xxx</select>

4.mybatis核心组件

    SqlSessionFactory
    SqlSession 
    Executor 执行器
    PooledResourceFactory
    SqlMapper

    

标签:缓存,关键字,二级缓存,解读,mybatis,sqlsession,源码,Mybatis,打开
From: https://blog.51cto.com/u_15951492/6038880

相关文章