开启二级缓存
1、mapper接口添加注解
@Repository @Mapper @CacheNamespace public interface HisAlarmDao extends BaseMapper<HisAlarmEntity> { }
2、application.yml开启二级缓存
#Mybatis-plus配置 mybatis-plus: configuration: cache-enabled: true #开启mybatis的二级缓存
3:启动类添加开启二级缓存注解
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) @EnableCaching public class AmsConfigApplication { public static void main(String[] args) { ConfigurableApplicationContext run = SpringApplication.run(AmsConfigApplication.class, args); } }
二级缓存作用于namespace针对于多个sqlsession共有,对于经常要获取最新数据的不建议使用二级缓存!