Spring Cacheable 注解不缓存null值

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

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

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

原文地址:https://www.cnblogs.com/zsg88/p/8707514.html