如何配置Velocity模板引擎以避免合并结果中自动回车?
我正在使用 Velocity (1.5) 使用模板+数据源生成一些文本。
我需要处理新行,因为合并结果不是 HTML 而是文本。
我有这种模板(beanInContext是一个数据矩阵,就像一个excel电子表格)
[begin TPL]
$beanInContext.prepare("someData");
$beanInContext.anotherOperation(1234);
#foreach( $row in $beanInContext.rows() )
#foreach($data in $row.data())
$data
#end
#end
[end TPL]
我希望合并结果是这样的:
a1 b1 c1
a2 b2 c2
...
但是我得到了类似的东西:
a1
b1
c1
a2
b2
c2
...
当使用类似的模板引擎时 freemarker,我使用 <#compress> 指令来实现这种格式。
有人知道如何配置速度引擎以避免这种回车混乱?
I'm using Velocity (1.5) to generate some text using template + data sources.
I need to take care of new lines since merging result is not HTML but text.
I have this kind of template (beanInContext is a matrix of data, like an excel spreadsheet)
[begin TPL]
$beanInContext.prepare("someData");
$beanInContext.anotherOperation(1234);
#foreach( $row in $beanInContext.rows() )
#foreach($data in $row.data())
$data
#end
#end
[end TPL]
And I expect the merging result to be like that:
a1 b1 c1
a2 b2 c2
...
But I got something like:
a1
b1
c1
a2
b2
c2
...
When using the similar template engine freemarker, I was using the <#compress> directive in order to achieve this kind of formatting.
Someone knows how to configure the velocity engine to avoid this kind of carriage return mess ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Velocity 与 JSP 非常相似,目前不提供空白管理方面的实际帮助。人们对此进行了很多讨论,但没有人加紧实施该功能。您会发现使用 JTidy 之类的东西来后处理 Velocity 输出要好得多。预计 Velocity 2.0 在空白处理方面会有所改进,但按照目前的速度,不要指望 Velocity 2.0 几年后会出现。工作进展缓慢。
如果空白控制很关键并且不能进行后处理,我建议使用 Freemarker。
如果您必须使用 Velocity,请注意 1.5 存在一些严重的性能问题。我强烈建议升级到1.7。
Velocity, much like JSP, does not currently provide practical assistance with whitespace management. It has been much discussed, but no one has ever stepped up to implement the feature. You will find it much better to use something like JTidy to post-process Velocity output. Expect to see improvement in whitespace handling for Velocity 2.0, but at this rate, don't expect Velocity 2.0 for a couple years. Work is slow.
If whitespace control is critical and post-processing is not an option, i would suggest using Freemarker.
And if you must use Velocity, beware that 1.5 has some significant performance issues. I strongly recommend upgrading to 1.7.
我可能不完全正确,但这是如何做到这一点的基本技巧:
I may not have this exactly right, yet here's the basic trick of how to do it: