开发者

Freemarker vs. Velocity [duplicate]

开发者 https://www.devze.com 2023-01-24 19:45 出处:网络
This question already has answers here: Velocity vs. FreeMarker [closed] (5 answers) Closed 9 years ago.
This question already has answers here: Velocity vs. FreeMarker [closed] (5 answers) Closed 9 years ago.

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开发者_如何学JAVA should look at instead?


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.


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:

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.


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 does not run on Android. Therefore, I'm currently converting my project to Velocity to make it compatible to mobile devices.

0

精彩评论

暂无评论...
验证码 换一张
取 消