放在實現類中:
第一種方式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);

