Java Freemarker 与 Velocity
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4137981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Freemarker vs. Velocity
提问by Tony the Pony
I'm trying to decide between Freemarker and Velocity to use as a template engine, any advantages/disadvantages you see regarding each?
我正在尝试在 Freemarker 和 Velocity 之间做出决定以用作模板引擎,您认为它们有什么优点/缺点吗?
Any alternatives that I should look at instead?
我应该考虑的任何替代方案?
采纳答案by Nathan Bubna
Velocity and Freemarker are both quite capable. Don't agonize over the choice. They have fairly different priorities behind their design, so once you get beyond basic templating, their feature-sets are hard to compare. Velocity's syntax is simpler and more distinct, Freemarker's heavier syntax allows them to support JSP libs. Velocity gives more freedom and ultimately more features through add-on projects like VelocityTools. Freemarker provides much better native whitespace handling, recent Velocity releases provide more interesting content controls (#define, #evaluate, #[[literal block]]#).
Velocity 和 Freemarker 都非常有能力。不要为选择而苦恼。他们的设计背后有相当不同的优先级,所以一旦你超越了基本的模板,他们的功能集就很难比较。Velocity 的语法更简单明了,Freemarker 更重的语法允许它们支持 JSP 库。Velocity 通过像VelocityTools这样的附加项目提供了更多的自由和最终更多的功能。Freemarker 提供了更好的原生空白处理,最近的 Velocity 版本提供了更有趣的内容控件(#define、#evaluate、#[[literal block]]#)。
As for performance, Velocity has made great gains in recent years, except perhaps in the initial template parse. But for any sane app where performance matters, you should have both engines set to cache templates and only parse once, making this less of an issue. In general, you will find that your performance with either engine depends far more upon the nature of your templates than the differences between the engines.
至于性能,Velocity 近年来取得了很大的进步,除了最初的模板解析。但是对于任何对性能很重要的健全应用程序,您应该将两个引擎都设置为缓存模板并且只解析一次,从而使这不是一个问题。通常,您会发现使用任一引擎的性能更多地取决于模板的性质,而不是引擎之间的差异。
StringTemplate is also respectable, though they are MVC nazis and can't match Velocity or Freemarker for features. ;) Your potential disappointment there is a bit higher than for either of the more popular template engines, of which neither is likely to disappoint much. Just grab one and go.
StringTemplate 也很受人尊敬,尽管它们是 MVC 纳粹分子并且无法与 Velocity 或 Freemarker 进行功能匹配。;) 您潜在的失望程度比任何一个更流行的模板引擎都要高一点,这两者都不太可能令人失望。拿一个就走。
回答by Andy
I prefer FreeMarker. I love the documentation, I can always find what I need. Overall I just think it is very powerful.
我更喜欢 FreeMarker。我喜欢文档,我总能找到我需要的东西。总的来说,我只是觉得它非常强大。
String Templateis another alternative.
字符串模板是另一种选择。
回答by meriton
There is a lengthy comparisonon the freemarker project page.
在 freemarker 项目页面上有一个冗长的比较。
Never having worked with velocity, I can not meaningfully compare the two, but I was so satisfied with freemarker that I saw no reason to look beyond it.
从来没有使用过速度,我无法对两者进行有意义的比较,但我对 freemarker 非常满意,我认为没有理由超越它。
回答by javamonkey79
It looks like thisis a decent rundown of the comparison. Though, it is a few years old.
看起来这是比较的一个体面的纲要。虽然,它已经几年了。
From the article:
从文章:
In conclusion
Both FreeMarker and Velocity are very capable template engines. Velocity seems to enjoy a larger user base, probably due to the fact that it is part of the Apache project. As I've shown in this article, though, FreeMarker is the more sophisticated and faster of the two. In basic operations both template engines are almost similar, providing an API that is easy to understand.
Both Velocity and FreeMarker are fairly easy to integrate into an application and offer good performance on small templates. Velocity slows down when parsing larger templates, which you might take into account when choosing a template engine for your project.
综上所述
FreeMarker 和 Velocity 都是非常强大的模板引擎。Velocity 似乎拥有更大的用户群,可能是因为它是 Apache 项目的一部分。不过,正如我在本文中所展示的,FreeMarker 是两者中更复杂和更快的。在基本操作上,两个模板引擎几乎相似,提供了易于理解的 API。
Velocity 和 FreeMarker 都相当容易集成到应用程序中,并在小模板上提供良好的性能。解析较大模板时速度会变慢,您在为项目选择模板引擎时可能会考虑到这一点。
回答by user208354
Freemarker does not run on Android. Therefore, I'm currently converting my project to Velocity to make it compatible to mobile devices.
Freemarker 不能在 Android 上运行。因此,我目前正在将我的项目转换为 Velocity 以使其与移动设备兼容。