Vic*_*ria 12 java string velocity substring
在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
Run Code Online (Sandbox Code Playgroud)
我希望这会返回True,因为$ url变量中存在1.44551子字符串.请有人告诉我哪里出错了?
Velocity在上下文映射中保存Objects值.只需添加toString以确保您在String上执行该contains方法:
#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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24710 次 |
| 最近记录: |