Freemarker 与 Velocity
我正在尝试在 Freemarker 和 Velocity 之间做出决定,以用作模板引擎,您认为两者有何优点/缺点?
我应该考虑哪些替代方案?
I'm trying to decide between Freemarker and Velocity to use as a template engine, any advantages/disadvantages you see regarding each?
Any alternatives that I should look at instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Velocity 和 Freemarker 都非常有能力。不要为选择而苦恼。他们的设计背后有相当不同的优先级,因此一旦超越基本模板,他们的功能集就很难比较。 Velocity 的语法更简单、更独特,Freemarker 更重的语法允许它们支持 JSP 库。 Velocity 通过 VelocityTools 等附加项目提供了更多自由,并最终提供了更多功能。 Freemarker 提供了更好的本机空白处理,最近的 Velocity 版本提供了更有趣的内容控件(#define、#evaluate、#[[literal block]]#)。
至于性能,Velocity 近年来取得了巨大的进步,除了最初的模板解析之外。但对于任何性能重要的理智应用程序,您应该将两个引擎设置为缓存模板并且仅解析一次,从而使这不再是一个问题。一般来说,您会发现使用任一引擎的性能更多地取决于模板的性质,而不是引擎之间的差异。
StringTemplate 也很受人尊敬,尽管它们是 MVC 纳粹并且无法与 Velocity 或 Freemarker 的功能相匹配。 ;)您可能会感到失望的程度比任何一个更流行的模板引擎都要高一些,而这两个模板引擎都不会让人太失望。只需抓住一个即可出发。
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]]#).
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.
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.
我更喜欢 FreeMarker。我喜欢这些文档,我总能找到我需要的东西。总的来说我只是觉得它非常强大。
字符串模板是另一种选择。
I prefer FreeMarker. I love the documentation, I can always find what I need. Overall I just think it is very powerful.
String Template is another alternative.
看起来这是比较的不错的概要。虽然,它已经有几年了。
来自文章:
It looks like this is a decent rundown of the comparison. Though, it is a few years old.
From the article:
freemarker 项目页面上有一个冗长的比较。
我从未使用过 Velocity,因此无法对两者进行有意义的比较,但我对 freemarker 非常满意,以至于我认为没有理由超越它。
There is a lengthy comparison on the freemarker project page.
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 不能在 Android 上运行。因此,我目前正在将我的项目转换为 Velocity,以使其兼容移动设备。
Freemarker does not run on Android. Therefore, I'm currently converting my project to Velocity to make it compatible to mobile devices.