检查字符串是否包含 Velocity 中的特定子字符串

2024-01-01

在 Velocity 中,我有一个名为 $url 的变量,其中包含以下字符串: [ContentId(2.7507), ContentId(2.7508), ContentId(1.44551)]

我想检查该字符串是否包含子字符串 1.44551。

这是我到目前为止编写的代码,但由于某种原因它返回 False:

#if($url.contains("1.44551"))
<p>The article content id is 1.44551</p>
#else
<p>The article content id isn't 1.44551</p>
#end

我希望它返回 True,因为 1.44551 子字符串存在于 $url 变量中。请有人告诉我哪里出了问题?


速度的值为Objects在上下文地图中。

如果要执行String方法,添加toString确保您在 String 上执行contains method:

 #if($url.toString().contains("1.44551"))
<p>The article content id is 1.44551</p>
#else
<p>The article content id isn't 1.44551</p>
#end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

检查字符串是否包含 Velocity 中的特定子字符串 的相关文章

随机推荐