Freemarker 与 Velocity

发布于 2024-10-01 02:01:45 字数 85 浏览 10 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

山色无中 2024-10-08 02:01:45

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.

白龙吟 2024-10-08 02:01:45

我更喜欢 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.

柒七 2024-10-08 02:01:45

看起来是比较的不错的概要。虽然,它已经有几年了。

来自文章:

总结

FreeMarker 和 Velocity 都非常好
强大的模板引擎。速度
似乎享有更大的用户群,
可能是因为它是
Apache 项目的一部分。正如我已经
不过,本文中显示,
FreeMarker 更复杂
并且两者中速度更快。基本情况下
两个模板引擎的操作都是
几乎类似,提供了一个API
很容易理解。

Velocity 和 FreeMarker 都是
相当容易集成到
应用并提供良好的性能
在小模板上。速度减慢
解析较大模板时下降,
当您可能会考虑到这一点时
选择适合您的模板引擎
项目。

It looks like this is 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.

荭秂 2024-10-08 02:01:45

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.

苏佲洛 2024-10-08 02:01:45

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文