本文共 310 字,大约阅读时间需要 1 分钟。
如下面代码所示,@Cacheable注解的unless属性已经为我们提供好了解决方案。
unless = "#result == null" 的意思就是,当返回值为null时,就不缓存
@Cacheable(cacheNames = {"single_book"},key = "#root.targetClass+'.'+#root.methodName+'.'+#p0", unless = "#result == null") public Book getBook(Long id){ return bookMapper.selectBookById(id); }
转载地址:http://hppkf.baihongyu.com/