StringTemplate 和 FreeMarker 之间的主要区别是什么?
网上似乎充满了 Velocity 和 FreeMarker 之间的比较,而且它们似乎相当等效。但StringTemplate和FreeMarker之间似乎几乎没有可比性!
那么,StringTemplate 和 FreeMarker 之间的主要区别是什么?
我对它们的用途是仅生成 HTML 页面。在这两者中,我希望 FreeMarker 更合适、更强大,因为这似乎是更常见的 - 但快速浏览一下,似乎 StringTemplate 实际上具有更合适的功能!
如果使用过两者的人有时间发表评论,那就太好了 - 对于实际细节,我可以并排阅读文档,但我想要一些开始的东西。
The net seems to be full of comparisons between Velocity and FreeMarker, and they seem to be reasonably equivalent. But there seems to be almost no comparisons between StringTemplate and FreeMarker!
So, what are the main differences between StringTemplate and FreeMarker?
My usage for them would be to generate HTML pages only. Out of the two, I would've expected FreeMarker to be the more suitable and more capable, as that seems to the more common one - but through a quick glance it seems that StringTemplate actually has more suitable features!
It would be great if someone who has used both would have time to comment - for the actual specifics, I can just read the documentation side by side, but I'd like something to get started with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在厌倦了 JSP 的“模板中的代码”模型后,我设计了 ST 来构建 jGuru。速度和朋友(即我认为的所有其他引擎)为您提供比您需要的更多的动力。我基本上使用了四个功能来构建 jGuru.com(如 paper< 中所述) /a>)。更多的功能是不必要的,并且会导致您将模型纠缠到模板中。如果您正在构建一次性原型,那没关系,任何引擎都可以。在这种情况下,模板中的代码是可以的,因为您不关心维护。
人们似乎忽略的另一件事是:图形设计师到底如何阅读模板中的代码?他们不能。那么,他们如何处理模板呢?即使更改某些元素的顺序也可能会破坏您的模型。你确实需要分离才能在商业环境中工作,除非你想要一个看起来像编码器构建 html 的网站;)
I designed ST to build jGuru after getting sick of the "code in template" model of JSP. Velocity and friends (i.e., every other engine i think) give you more power than you need. I used basically four features to build jGuru.com (as described in paper). More features are unnecessary and lead you to entangle your model into the template. If you're building a one-off prototype, that's ok and any engine is fine. Code in templates is ok in that case since you don't care about maintenance.
Another thing people seem to ignore: how the hell can a graphics designer read code in templates? They can't. So, how can they work on the templates then? Even changing the order of some elements can break your model. You really need the separation to work in commercial environment, unless you want a site that looks like a coder built the html ;)
主要区别在于 StringTemplate 严格强制执行模型视图分离,并且您不能将逻辑放入模板中,而 FreeMarker 允许您将完整的逻辑放入模板中。这至少在开始时会使其更难以使用,但它更有用可扩展。例如,如果您正在生成代码并且模板中没有逻辑,则为另一种语言生成另一个端口就不那么繁琐,因为您不必在每个模板中复制逻辑。
Terence Parr 的一篇论文解释了模型视图分离
The main difference is that StringTemplate strictly enforces model-view separation and you can't put logic in the templates and FreeMarker lets you put full of logic in the templates.. This at least at the beginning make it more difficult to use but it's more scalable. For example if you are generating code and you have no logic in the templates generating another port for another language is less tedious because you haven't to replicate logic in each template.
There's a paper from Terence Parr that explains the benefits from model-view separation