@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中效果值如图