gpt4 book ai didi

java - Apache Spring - 具有多行属性值的 Bean

转载 作者:行者123 更新时间:2023-12-01 20:05:46 24 4
gpt4 key购买 nike

有没有办法分解 Spring bean 的属性值,使其位于多行上?

<bean>
<property name="something" value="Hello, this is a red fox jumping over a not very brown cow.">
</bean>

我知道在 Java 属性文件中,我可以在每行末尾放置一个“\”,但以下内容不适用于 Spring bean 的属性值:

<bean>
<property name="something" value="Hello, this is a \
red fox jumping over a \
not very brown cow.">
</bean>

最佳答案

XML 属性允许跨行,并且解析器将非空格空白字符替换为空格。因此,对于您的示例,您可以使用:

<bean name="foo" class="Foo">
<property name="bah" value=
"Hello, this is a
red fox jumping over a
not very brown cow." />
</bean>

那么“foo”中“bah”的值为

"Hello, this is a red fox jumping over a not very brown cow."

如果你尝试让它像这样整洁

<bean name="foo" class="Foo">
<property name="bah" value=
"Hello, this is a
red fox jumping over a
not very brown cow." />
</bean>

您将在解析结果中获得额外的空格字符。

Hello, this is a    red fox jumping over a    not very brown cow.

关于java - Apache Spring - 具有多行属性值的 Bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47402705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com