springboot和cache

74 阅读1分钟

整合springcache

引入依赖

 <!-- 实现对 Caches 的自动化配置 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>

<!--整合redis-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

启动类引入注解@EnableCaching

@SpringBootApplication
@EnableCaching
public class CommodityApplication {

    public static void main(String[] args) {
        SpringApplication.run(CommodityApplication.class, args);
    }
}

使用缓存

@Cacheable(cacheNames = "order", key = "#order.id")
public OrderVo selectDetailById(Order order) {
    return orderMapper.selectDetailById(order);
}

www.iocoder.cn/Spring-Boot…