Java 如何在SpEL中转义值?
我正在用XML编写一些SpEL语句,但无法让解析器确定何时需要转义字符 我尝试了以下几点:Java 如何在SpEL中转义值?,java,spring,spring-el,Java,Spring,Spring El,我正在用XML编写一些SpEL语句,但无法让解析器确定何时需要转义字符 我尝试了以下几点: <... property="someProperty" value="#{ someBean.aMethodOnTheBean('st\'ring') }" /> 然而,在\'中添加似乎并没有逃过那个单引号,我一直收到一个解析器异常 有没有办法转义这些值?我修改为: .... value="#{ someBean.aMethodOnTheBean("st'ring") }" 这是可
<... property="someProperty" value="#{ someBean.aMethodOnTheBean('st\'ring') }" />
然而,在\'中添加似乎并没有逃过那个单引号,我一直收到一个解析器异常
有没有办法转义这些值?我修改为:
.... 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>
“#{anotherBean.methodOnBean(“某些字符串”)}”
来自:
“将单个引用本身放入
字符串使用两个单引号
人物。”
expression='something=''+somethod.getValue+'''''
FWIW,从3.2版开始,SpEL支持双引号。
{someBean.amethodethebean(T(org.apache.commons.lang.StringEscapeUtils.escapeJavaScript(“ad'sf”))可以工作,但不是很好的尝试!顺便说一句,这种方法在过去的一个例子中有记录。此外,这可能是谁在使用的一个选项(尽管我不知道如何在这种情况下正确使用它,所以我最终直接转义了
.properties
文件中的值)。是因为内容太腐败还是我弄错了?我很确定:
不是有效的XML。