如何开启mybatis的默认二级缓存
1、mybaits的二级缓存是mapper范围级别,要在具体的mapper.xml中开启二级缓存。
在核心配置文件 中加入:
<setting name="cacheEnabled"value="true"/>
<!-- 全局配置参数,需要时再设置 -->
<settings>
<!-- 开启二级缓存 默认值为true -->
<setting name="cacheEnabled" value="true"/>
</settings>
2、cacheEnabled 介绍
描述 : cacheEnabled
允许值: 对在此配置文件下的所有cache 进行全局性开/关设置。
默认值 (true/false): true
3、mpper.xml中开启二缓存,mapper.xml下的sql执行完成会存储到它的缓存区域(HashMap)。
<mapper namespace="cn.hpu.mybatis.mapper.UserMapper">
<!-- 开启本mapper namespace下的二级缓存 -->
<cache></cache>
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。