key 拼接静态常量字符串,注意:

  • 写成 key = Consts.PEEFIX + "#result.id" 这样直接拼接 是错误的
  • spring el 在解析时报异常

正确写法如下: 您可以做参考

// key = "'"+ Consts.PREFIX+"'"+"+#result.id"  // 这个写法也是成立的
@CachePut(value = "RoleCache",condition = "#result != 'null'", key = "{'" + Consts.PREFIX + "', #result.id}")
@Override
public Role addRole(Role role) {
    boolean save = roleService.save(role);
    if (save){
        return role;
    }
    return null;
}
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐