14

XML でいくつかの SpEL ステートメントを作成していますが、いつ文字をエスケープする必要があるかをパーサーに判断させることができません。

私は次のことを試みました:

<... property="someProperty" value="#{ someBean.aMethodOnTheBean('st\'ring') }" />

ただし、\' を追加しても、その一重引用符がエスケープされないようで、パーサー例外が発生し続けます。

これらの値をエスケープする方法はありますか?

4

3 に答える 3

21

ドキュメントから:

「単一引用符自体を文字列に入れるには、2 つの単一引用符文字を使用します。」

expression = 'something = ''' + someMethod.getValue + ''''

于 2011-06-01T19:38:39.127 に答える
0

私は次のように変更しました:

.... value="#{ someBean.aMethodOnTheBean("st'ring") }" 

これは機能しますが、以前に二重引用符を使用して文字列値を SpEL 関数に入力するときに問題があったことを誤って思い出しました。

以下はスキーマ定義です。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"
       default-lazy-init="true"
       default-init-method="initialize">

XML は Eclipse で適切に検証されます。ただし、私の単純化した例は有効ではありませんでした。お詫び申し上げます。私は実際に次のように値を設定しています:

<bean id="someBean" class="someClass">
    <property name="someList">
        <list>
            <value>"#{ anotherBean.methodOnBean("some'String") }"</value>
        </list>
    </property>
</bean>
于 2010-11-29T21:53:27.397 に答える
0

FWIW、SpEL はバージョン 3.2 の時点で二重引用符をサポートしています。 SPR-9620

于 2015-06-19T14:16:21.490 に答える