我正在用XML编写一些SpEL语句,但是我无法让解析器确定何时需要转义字符。
我尝试了以下几种方法:
<... property="someProperty" value="#{ someBean.aMethodOnTheBean('st\'ring') }" />但是,添加\‘似乎无法避免这个单引号,并且我一直收到解析器异常。
有什么方法可以避开这些值吗?
发布于 2011-06-02 03:38:39
在documentation中:
“要将单引号放入字符串中,请使用两个单引号字符。”
expression = 'something = ''' + someMethod.getValue + ''''
发布于 2010-11-30 05:53:27
我修改为:
.... 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>发布于 2015-06-19 22:16:21
FWIW,SpEL从3.2版开始支持双引号。SPR-9620
https://stackoverflow.com/questions/4308247
复制相似问题