Spring Cacheable 注解不缓存null值

用Cacheable注解时,发现空值,也会被缓存下来。如果我们期望空值不被缓存,可以做如下设置:

@Cacheable(key = "#id", unless="#result == null")  
public XXXPO getValue(int id) {  
   //get 
}

unless="#result == null"  //当条件为true时,不保存对象

 

posted @ 2018-04-03 11:34  猪脚踏浪  阅读(2268)  评论(0编辑  收藏  举报