@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中效果值如图
在这里插入图片描述


版权声明:本文为weixin_44488164原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。