org.springframework.boot spring-boot-starter-cache net.sf.ehcache ehcache
@Mapperpublic interface UserMapper { void insertUser(User user); void updateUser(User user); void deleteUser(User user); @Cacheable(value="user") User queryUser(Integer id);
@SpringBootApplication@MapperScan("com.example.zs.mapper")@EnableCachingpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
resources下的ehcache.xml:
application.properties: spring.cache.ehcache.config=classpath:ehcache.xml
public class User implements Serializable {
@Cacheable的使用
@CacheEvict:清除缓存