0
点赞
收藏
分享

微信扫一扫

Spring 缓存注解 @Cacheable 使用两个或多个参数作为缓存的 key

@Cacheable使用两个或多个参数作为缓存的key

常见的如分页查询:使用单引号指定分割符,最终会拼接为一个字符串

@Cacheable(key = "#page+'-'+#pageSize")
public List<User> findAllUsers(int page,int pageSize) {
int pageStart = (page-1)*pageSize;
return userMapper.findAllUsers(pageStart,pageSize);
}

当然还可以使用单引号自定义字符串作为缓存的key值

@Cacheable(key = "'countUsers'")
public int countUsers() {
return userMapper.countUsers();
}

在redis中效果值如图


Spring 缓存注解 @Cacheable 使用两个或多个参数作为缓存的 key_字符串


Kotlin 开发者社区


Spring 缓存注解 @Cacheable 使用两个或多个参数作为缓存的 key_单引号_02


国内第一Kotlin 开发者社区公众号,主要分享、交流 Kotlin 编程语言、Spring Boot、Android、React.js/Node.js、函数式编程、编程思想等相关主题。

越是喧嚣的世界,越需要宁静的思考。


举报

相关推荐

0 条评论