@Cacheable 在類上和接口上注解,參數值讀取方式


 

放在實現類中:

第一種方式key = "'user_id_'+#id",unless = "#result == null")

@Cacheable(value = "user",key = "'user_id_'+#id",unless = "#result == null")
public User selectByPrimaryKey(Integer id) {
return userMapper.selectByPrimaryKey(id);
}

可以讀到參數值Integer id

第二種方式key = "'user_id_'+#p0",unless = "#result == null")

@Cacheable(value = "user",key = "'user_id_'+#id",unless = "#result == null")
public User selectByPrimaryKey(Integer id) {
return userMapper.selectByPrimaryKey(id);
}

也可以讀到參數值Integer id

 

放在接口上:

第一種方式可以讀到Integer id值

@Cacheable(value = "user",key = "'user_id_'+#p0",unless = "#result == null")
User selectByPrimaryKey(Integer id);

 

--接口數據

--Redis緩存數據

 

第二種方式讀不到Integer id值,值是null,

@Cacheable(value = "user",key = "'user_id_'+#id",unless = "#result == null")
User selectByPrimaryKey(Integer id);

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM