<mappernamespace="com.example.mapper.UserMapper"> <!-- 配置二级缓存 --> <cacheeviction="LRU"flushInterval="60000"size="512"readOnly="true"/> <!-- 配置SQL语句 --> <selectid="selectUserById"resultType="com.example.pojo.User"> SELECT * FROM user WHERE id = #{id} </select> </mapper>
2.2.3.2 注解配置
在Mapper接口中使用@CacheNamespace注解配置缓存策略。
示例:
java
1 2 3 4 5
@CacheNamespace(eviction=EvictionType.LRU, flushInterval=60000, size=512, readOnly=true) publicinterfaceUserMapper { @Select("SELECT * FROM user WHERE id = #{id}") User selectUserById(Integer id); }
<mappernamespace="com.example.mapper.UserMapper"> <!-- 配置二级缓存 --> <cacheeviction="LRU"flushInterval="60000"size="512"readOnly="true"/> <!-- 配置SQL语句 --> <selectid="selectUserById"resultType="com.example.pojo.User"useCache="false"> SELECT * FROM user WHERE id = #{id} </select> </mapper>
2.2.6.2 注解配置
示例:
java
1 2 3 4 5 6
@CacheNamespace(eviction=EvictionType.LRU, flushInterval=60000, size=512, readOnly=true) publicinterfaceUserMapper { @Select("SELECT * FROM user WHERE id = #{id}") @Options(useCache = false) User selectUserById(Integer id); }
条