Spring @Cacheable当返回值为null时报错解决方案

如下面代码所示,@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);
    }

猜你喜欢

转载自blog.csdn.net/xl_1803/article/details/112114631