SpEL 表达式利用 "contains()" 字符串方法

SpEL expression to utilize "contains()" string method

我正在尝试利用 String.contains() 以根据存储在 jobExecutionContext 中的文件名动态创建字段值。 key/value (file=>nameOfFile.txt) 对肯定存在于上下文中,因为我在其他地方使用它。

我正在尝试使用以下 SpEL 表达式执行此操作:

<property name="subject" value="#{((String)jobExecutionContext['file']).contains('monk') ? 'Monkey' : 'Banana'} kind of file" />

但是我收到错误:

Expression parsing failed; nested exception is org.springframework.expression.spel.SpelParseException: EL1043E:(pos 9): Unexpected token.  Expected 'rparen())' but was 'identifier'

异常是因为“(String)”,你可以这样做:

<util:map id="fruit">
    <entry key="banana" value="#{89.7}"/>
    <entry key="apple" value="efg"/>
    <entry key="orange" value="lmn"/>
</util:map>
<bean id="hello" class="com.choiwan.Hello">
    <property name="name" value="#{(fruit['banana']+'').contains('89')?'Monkey':'Banana'} kind of file"/>
</bean>