@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-2025 CODEPRJ.COM