依赖
<!-- 开启缓存 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
开启缓存
@SpringBootApplication
@EnableCaching
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
使用
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept>
implements DeptService {
@Resource
private DeptMapper mapper;
@Cacheable(value = "cacheSpace" ,key="#deptno")
@Override
public Dept getByDeptCode(Integer deptno) {
return mapper.getByDeptCode(deptno);
}
}