StringTemplate 可以迭代“值”吗?在字符串中?
我有一个由多个以逗号分隔的字符串组成的字符串。使用 StringTemplate,是否有一种简单的方法可以为这个外部字符串中的每个“值”编写单独的行?
例如,我有:
String layers = "ADM,NAV";
并且我想输出:
ADM,Y,
NAV,Y,
我怀疑模板看起来(如果可能的话)是这样的:
$layers.split(","): {layer | $layer$,Y, }$
这是我发现的一个可能相关的示例,说明如何为集合中的每个对象编写一行:
<ul>
$orders: {order|
<li>Order $order.OrderId$</li>
}$
</ul>
但是,我不能只用Java代码中的字符串构建一个集合 - 它必须仍然是一个以逗号分隔的字符串。有什么想法吗?
谢谢!
I have a String made up of several Strings seperated by commas. Using StringTemplate, is there an easy way to write a seperate line for each 'value' in this outer String?
For example, I have:
String layers = "ADM,NAV";
and I want to output:
ADM,Y,
NAV,Y,
I suspect the template would look (if it's possible) something like this:
$layers.split(","): {layer | $layer$,Y, }$
Here's a somewhat-possibly related example I found of how write a line for each object in a collection:
<ul>
$orders: {order|
<li>Order $order.OrderIdlt;/li>
}$
</ul>
However, I cannot just build a collection out of the String in my Java code - it must remain a comma-seperated String. Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 StringTemplate: template 的哲学这是不可能的引擎的目的是将表示与业务逻辑分开。在您的情况下,拆分字符串是业务逻辑,无法在模板中执行。
It is not possible according to the philosophy of StringTemplate: template engine's purpose is to separate representation from business logic. In your case splitting string is business logic and cannot be performed in template.