Jar listItem的StringTemplate使用
我正试图让这个简单的例子起作用,下面是示例代码.stg文件Jar listItem的StringTemplate使用,jar,stringtemplate,Jar,Stringtemplate,我正试图让这个简单的例子起作用,下面是示例代码.stg文件 group list-demo; htmListExample(xmen) ::= << Example 5: <html> <body> <h1>Original X-Men</h1> <ul> $xmen:listItem()$ </ul> </body&
group list-demo;
htmListExample(xmen) ::= <<
Example 5:
<html>
<body>
<h1>Original X-Men</h1>
<ul>
$xmen:listItem()$
</ul>
</body>
</html>
>>
listItem() ::= <<
<li>$it$</li>
>>
组列表演示;
htmListExample(xmen):=>
listItem():=>
我的Java代码:
STGroup group = new STGroupFile("/myTemplate2.stg",'$','$');
ST template = group.getInstanceOf("htmListExample");
List<String> xmen = Arrays.asList("Jean Gray", "Cyclops");
template.add("xmen", xmen);
System.out.println(template.render().toString());
STGroup group=newstgroupfile(“/myTemplate2.stg”、“$”、“$”);
ST template=group.getInstanceOf(“htmListExample”);
List xmen=Arrays.asList(“Jean Gray”、“Cyclops”);
添加模板(“xmen”,xmen);
System.out.println(template.render().toString());
以及输出:
context [/htmListExample] 6:18 passed 1 arg(s) to template /listItem with 0 declared arg(s)
context [/htmListExample] 6:13 passed 1 arg(s) to template /listItem with 0 declared arg(s)
context [/htmListExample] 6:13 passed 1 arg(s) to template /listItem with 0 declared arg(s)
context [/htmListExample /listItem] 2:5 attribute it isn't defined
context [/htmListExample /listItem] 2:5 attribute it isn't defined
Example 5:
<html>
<body>
<h1>Original X-Men</h1>
<ul>
<li></li>
<li></li>
</ul>
</body>
</html>
context[/htmListExample]6:18向模板/listItem传递了1个参数,其中声明了0个参数
context[/htmListExample]6:13将1个参数传递给声明了0个参数的模板/listItem
context[/htmListExample]6:13将1个参数传递给声明了0个参数的模板/listItem
上下文[/htmListExample/listItem]2:5属性未定义
上下文[/htmListExample/listItem]2:5属性未定义
例5:
原版X战警
有人能解释一下为什么listItem()无法识别吗?我正在使用ST-4.0.7.jar
感谢在StringTemplate 4中,映射操作符
:
将集合映射到使用一个参数的模板。您需要为listItem
模板声明it
参数:
listItem(it) ::= <<
<li>$it$</li>
>>
listItem(it):=>
您在输出中看到的警告如下所示:
它
参数,但在列表项
中引用了它是的。就这样。我想我是在找一个老例子。谢谢