首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何转义SpEL中的值?

如何转义SpEL中的值?
EN

Stack Overflow用户
提问于 2010-11-30 05:23:19
回答 3查看 16.5K关注 0票数 14

我正在用XML编写一些SpEL语句,但是我无法让解析器确定何时需要转义字符。

我尝试了以下几种方法:

代码语言:javascript
运行
复制
<... property="someProperty" value="#{ someBean.aMethodOnTheBean('st\'ring') }" />

但是,添加\‘似乎无法避免这个单引号,并且我一直收到解析器异常。

有什么方法可以避开这些值吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-06-02 03:38:39

documentation中:

“要将单引号放入字符串中,请使用两个单引号字符。”

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

票数 21
EN

Stack Overflow用户

发布于 2010-11-30 05:53:27

我修改为:

代码语言:javascript
运行
复制
.... value="#{ someBean.aMethodOnTheBean("st'ring") }" 

这是可行的,我错误地记得在前面的SpEL函数中使用双引号输入字符串值时出现了问题。

以下是模式定义:

代码语言:javascript
运行
复制
<?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中进行了正确的验证。然而,我的简化示例是无效的--我很抱歉,并很好地抓住了它。我实际上是这样设置这个值的:

代码语言:javascript
运行
复制
<bean id="someBean" class="someClass">
    <property name="someList">
        <list>
            <value>"#{ anotherBean.methodOnBean("some'String") }"</value>
        </list>
    </property>
</bean>
票数 0
EN

Stack Overflow用户

发布于 2015-06-19 22:16:21

FWIW,SpEL从3.2版开始支持双引号。SPR-9620

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4308247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档