0

How should I escape the following Java code, so I can use it in a Spring-EL expression?

Java:

.replaceAll("[\\p{Punct}&&[^\"|\\]|\\[|+|\\-|:|(|)|_|~|.|,|%|?]]", " ")

Spring-EL, which doesn't parse:

<int:transformer 
    input-channel="splitTitles" 
    output-channel="lowercasedTitles" 
    expression="payload.toLowerCase().replaceAll('[\\p{Punct}&&[^\"|\\]|\\[|+|\\-|:|(|)|_|~|.|,|%|?]]').trim()">
</int:transformer>
4

1 回答 1

0

在基于 XML 的文件中指定属性值时,您必须转义特殊字符(即 & = &amp;、 " = &quot;)。此外,您没有为 replaceAll 方法调用指定第二个参数。试试这个,

<int:transformer 
        input-channel="splitTitles" 
        output-channel="lowercasedTitles" 
        expression="payload.toLowerCase().replaceAll('[\\p{Punct}&amp;&amp;[^\&quot;|\\]|\\[|+|\\-|:|(|)|_|~|.|,|%|?]]', ' ').trim()">
    </int:transformer>
于 2012-07-23T12:37:16.887 回答