-
添加依赖
org.springframework.boot spring-boot-starter-data-redis org.springframework.boot spring-boot-starter-cache -
application.properties
spring.redis.host=127.0.0.1
spring.redis.pool.max-idle=8
spring.redis.pool.min-idle=0
spring.redis.pool.max-active=8
spring.redis.pool.max-wait=-1 -
Aplication
@SpringBootApplication@EnableCachingpublic class Application {public static void main(String[] args) {SpringApplication.run(Application.class,args);}}
-
mapper
@Component //为了消除Controller里面的红线警告@Mapper@CacheConfig(cacheNames = "users")public interface UserMapper {@CacheableUser get(Long id);void insert(User user);void update(User user);List
list(UserQueryObject qo);void delete(Long id);User findByUsername(String username);Set getRoleNamesByUserId(Long userId);Set getPermissionsNameByRoleNames(@Param("roleNames") Set roleNames);}
在需要缓存的地方添加@Cacheable注解