0

我正在使用带有咖啡因缓存的 Spring Boot。我的缓存键是 Long 并且我需要键是例如:“1234-RULE”,其中 1234 是 Long 对象,-RULE 只是一个后缀。我尝试了以下方法来实现这一目标:

private final static String RULE_KEY = "#rule.id.concat('-RULE')";

@Cacheable(value = CacheConfig.RULE_OFFSET, key = RULE_KEY)
public BigDecimal getRuleOffset(final Rule rule) {

  // some code to fetch the value and return it

}

在调试时,我收到错误:

Error occurred while performing the request. Message: EL1004E: Method call: Method concat(java.lang.String) cannot be found on type java.lang.Long

我的 rule.id 是 Long,我用来连接 id 和后缀的表达式似乎不正确。你能告诉我如何在这里为我的用例连接一个长字符串。

4

1 回答 1

1

EL 的文档有时可能有点奇怪,但您可以在+这里用作连接运算符:

#rule.id + '-RULE'
于 2020-07-16T13:54:03.523 回答