1) 当参数只是id, 但又想使用对象时,如何使用呢?

  此时可借助额外的方法,该方法必须是public

  根据文档提供的说明,可以使用#root下的一些方法:

 spring cache


   @CacheEvict(value = CacheName.HOME_NAV_LIST, key = "#root.target.getDeclaredNav(#req.navId).clientType")
   public Boolean deleteNav(ReqNavId req) { }
   
   public Nav getDeclaredNav(String navId) {
        return navMapper.selectByPrimaryKey(navId);
    }

2)使用spring cache 整合redis:
     ##  @Cacheable(sync 与 unless不能同时使用)

    ##  要缓存的JavaBean必须实现Serializable接口,因为Spring会将对象先序列化再存入 Redis

       否则抛出异常:org.springframework.data.redis.serializer.SerializationException cannot be cast to org.springframework.cache.interceptor.CacheOperationInvoker$ThrowableWrapper
   

 

相关文章: