我有一张爪哇地图
Map<String, Object> model = new HashMap<>();
此映射的每个(键、值)对都是一个urls列表:
List<String> thumbnailImgUrl = new ArrayList<>();
for (....) {
thumbnailUrl.add(url);
}
model.put("photoUrl", thumbnailImgUrl);
我将对象“模型”传递给StringTemplate。
如何访问字符串模板中的单个urls?
Notification(model) ::= <<
{how can I access the individual urls here?}
>>
发布于 2014-05-21 08:14:32
我已经将这个问题标记为重复,但是为了防止有更多的注释或答案讨论如何在Java中进行转换或迭代,回答问题的正确的StringTemplate模板是
Notification(model) ::= <<
<model.photoUrl:{v | model.photoUrl[<i>]=<v> }>
>>
map.key
访问映射中的项,<list:{v|<v>}>
部件在列表上迭代,并对列表的每个元素应用一个非殖子模板。
发布于 2016-04-10 06:16:04
要做到这一点,您必须以以下方式使用循环和临时变量:
Notification(model) ::= <<
$model.thumbnailImgUrl: {thumbnailImgUrl | URL is :- $thumbnailImgUrl.url$}$
>>
我希望这能帮到你。
发布于 2014-05-21 07:28:03
获取对象并将其转换为类类型-
List<String> urls = (List<String>)(model.get("photoUrl"));
https://stackoverflow.com/questions/23776477
复制相似问题