Spring MVC + FreeMarker:如何渲染选项标签?
Spring 3 MVC 文档声明选项标签可以像这样呈现:
<tr>
<td>Country:</td>
<td>
<form:select path="country">
<form:options items="${countryList}" itemValue="code" itemLabel="name"/>
</form:select>
</td>
</tr>
我正在使用 FreeMarker 和 Spring MVC,所以我将其解释为:
<tr>
<td>Place:</td>
<td>
<@form.select path="place">
<@form.options items="${places}" itemValue="id" itemLabel="name"/>
</@form.select>
</td>
</tr>
当我点击页面时,我得到以下异常:
freemarker.core.NonStringException: Error on line 40, column 73 in event.ftl
Expecting a string, date or number here, Expression places is instead a freemarker.template.SimpleSequence
我应该使用什么来代替 ${places}在我的 FreeMarker 模板中,以便上面的工作正常吗?
谢谢。
The Spring 3 MVC docs state that option tags can be rendered like this:
<tr>
<td>Country:</td>
<td>
<form:select path="country">
<form:options items="${countryList}" itemValue="code" itemLabel="name"/>
</form:select>
</td>
</tr>
I am using FreeMarker with Spring MVC, so I interpret this as:
<tr>
<td>Place:</td>
<td>
<@form.select path="place">
<@form.options items="${places}" itemValue="id" itemLabel="name"/>
</@form.select>
</td>
</tr>
When I hit the page I get the following exception:
freemarker.core.NonStringException: Error on line 40, column 73 in event.ftl
Expecting a string, date or number here, Expression places is instead a freemarker.template.SimpleSequence
What should I use instead of ${places} in my FreeMarker template so that the above works?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我一直在寻找完全相同的东西。我不知道为什么它不包含在 Spring 的 Freemarker 宏库中,但幸运的是它很容易实现:最佳实践是启动您自己的宏库(例如
mylib.ftl
)并将宏放在那里:然后您可以在 Freemarker 模板中使用新宏,如下所示:
HTH
I was looking for exactly the same thing. I've no idea why this isn't included in Spring's Freemarker macro library, but fortunately enough it's quite easy to implement: Best practice would be to start your own macro library (say
mylib.ftl
for example) and put the macro there:You can then use your new macro in your Freemarker template like so:
HTH
您可以尝试以下方法(未亲自测试)
希望这会有所帮助!
You could try the following (not tested personally)
Hope this helps!
有点奇怪,但它有效。
这样您就可以
a little bit weird but it works.
so you will have