我在 Camel route 使用这个表达式:
.when(simple("${body.updateSeq} > ${property.PrevUpdateSeq} + 1"))
.to("direct:someError")
然而,它对
+
符号感到害怕。org.apache.camel.language.simple.types.SimpleIllegalSyntaxException: Unexpected token + at location 46
${body.updateSeq} > ${property.PrevUpdateSeq} + 1
*
我如何构造这个表达式,假设它从消息正文上 POJO 的 getter
getUpdateSeq
获取一个值,并将其压缩为 Exchange 上的一个属性(加 1)。
最佳答案
Simple Languate 中包含的 Apache Camel 本身不支持 +
操作。然而,它提供了一个 ++
增量运算符,它要求左侧是一个函数。
最简单的解决方案是将操作重构为 bean
public class NextValueService
{
@Handler
public Integer nextValue(Integer value)
{
return new Integer(value.intValue() + 1);
}
}
并在您的 route 使用它,如下所示:
.when(simple("${body.updateSeq} > ${bean:nextValueService?method=nextValue(property.PrevUpdateSeq)"}))
.to("direct:someError")
使用 f.e. 切换简单语言JavaScript 或 Groovy 也应该有助于处理这个问题。
关于java - "Simple"表达式语言 - 算术运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20973511/