Spring @Cacheable当返回值为null时报错解决方案
如下面代码所示,@Cacheable注解的unless属性已经为我们提供好了解决方案。unless = "#result == null" 的意思就是,当返回值为null时,就不缓存@Cacheable(cacheNames = {"single_book"},key = "#root.targetClass+'.'+#root.methodName+'.'+#p0",unless = "#res
·
如下面代码所示,@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);
}
更多推荐
已为社区贡献1条内容
所有评论(0)