Velocity 与 Apache Tiles
什么更好? 我们将开始一个新的网络项目,这是选择哪种技术的问题。 项目包括Spring MVC + WebFlow。 在支持、扩展、性能方面有什么好的/坏的经验吗?
谢谢。
What's better?
We are going to start a new web project and it's a question which technology to choose.
Project includes Spring MVC + WebFlow.
Any good/bad experience in support, extending, performance?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Velocity 和 Tiles 是两种不同的野兽——Tiles 是布局引擎,而 Velocity 是模板引擎。它们在功能上没有任何交叉点。
从你的问题我可以猜测你可能不会使用JSP。这是一个明智之举。 Velocity 是模板引擎之一,它的工作非常出色。
如果您选择遵循模板引擎路线进行视图,请查看commentit。这是我创建的一个小型、简单且快速的布局引擎。它可能完美地满足您的目的。
Velocity and Tiles are two different beasts — Tiles is a layout engine and Velocity is a template engine. They do not intersect anywhere in terms of functionality.
From your question I can guess you probably won't be using JSP. That's a smart move. Velocity is one of the template engines out there and it does an absolutely splendid job.
And if you choose to follow the template engine route for your view, then check out commentit. It's a small, simple and fast layout engine I created. It might serve your purpose perfectly.
您想如何比较 Tiles 和 Velocity? - Tiles是一种组合页面片段的方式,而Velocity是一个更完整的模板引擎,比Tiles更好地与JSP相媲美。
无论如何:我将 Spring MVC 与 Tiles 和 JSP 一起使用:它工作得很好,节省了大量时间(仅使用 JSP,或 JSP 与 Sitemash),而且我没有注意到任何性能问题。 (但 Web 应用程序从未在高负载下使用过。)
How do you want compare Tiles with Velocity? - Tiles is a way to compose page fragments, while Veleocity is a more complete template engine, better comparable with JSP than Tiles.
Anyway: I used Spring MVC with Tiles and JSP: It worked greatly, saved a lot of time (toward just using JSP, or JSP with Sitemash), and I did not noticed any performance problems. (But the web application was never used under high load.)
如果您想将一些单独的
HTML
文件放在模板中(即,您有一个单独的页眉、页脚、侧边栏页面,并且您想要将它们放在一起并以类似报纸的格式展示)。如果您想从
Java
后端引入动态内容并将这些值注入到完整的HTML
页面(即您有一个 < code>HTML 表来显示选定的汽车,并且所有汽车都存储在数据库中,使用JPA
,您可以从数据库中获取汽车数据,并将其存储到数据库中。在EJB
Bean、Spring @Component
或类似组件中维护的List
然后,使用 Velocity,您可以将该信息存储为Map
中的存储桶项,并使用VTL
标记引用Map
中的键值项,以便可以渲染它们作为HTML
响应的一部分,为了实现上述目的,Velocity 将自己定位为一个完全的 Front Controller Servlet,或者由另一个 MVC 框架包装(即 Spring MVC 提供了一个 View Resolver,它包装了由 提供的功能)。 Velocity Servlet)。
HTML
请求通过web.xml
配置定向到 Velocity Servlet 或替代 MVC 框架 Servlet。作为 servlet 响应的一部分,您的预烘焙HTML
视图(带有 VelocityVTL
标记)会通过Map
数据进行丰富。简而言之,
Velocity 与 JSP 在同一领域展开竞争。
Tiles 更类似于页面嵌入。在 PHP 领域,Smarty 是一个很受欢迎的表兄弟。
您无法在它们之间进行选择,但很可能两者都使用。
Use Tiles if you have some seperate
HTML
files that you want to bring together in a Template (i.e. you have a seperate page for a Header, Footer, Sidebar and you want to bring them together and display them in a sort of Newspaper-like format).Use Velocity if you want to bring dynamic content across from a
Java
backend and inject those values into a fullHTML
page (i.e. you have aHTML
table to display a selection of Cars, and all of your cars are stored in a Database. UsingJPA
, you could get that Car data out of the database, and into aList<Car>
maintained in anEJB
Bean,Spring @Component
, or similar. Then, using Velocity, you can store that information as the bucket item inside aMap
, and use theVTL
mark-up to refer to the key value items in theMap
so that they can be rendered as part of theHTML
response.To achieve the above, Velocity positions itself as an outright Front Controller Servlet, or is wrapped by another MVC framework (i.e. Spring MVC provides a View Resolver which wraps the functionality provided by a Velocity Servlet).
HTML
requests are directed to the Velocity Servlet or alternative MVC Framework Servlet viaweb.xml
configuration. As part of the servlet response, your pre-bakedHTML
view, complete with VelocityVTL
mark-up, is enriched withMap
data.Effectively, and in summary:
Velocity competes in the same space as JSP.
Tiles is more akin to page transclusion. In the PHP space, Smarty is a popular cousin.
You don't choose between them, but very well could use both.
Tiles 2.2 有一个 Velocity 插件,因此您可以同时使用两者 - 通过 Velocity,您将访问上下文并像 JSP 一样动态构建您的积木,而tiles会将您的网站积木组合在一起。然而,Tiles 不允许做很多事情(至少我还没有发现它们),并且与 Spring 或 JSF 等文档相比,它的文档非常陈旧且糟糕。所以你可以考虑使用不同的技术。
我当前的项目中有 Tiles 参考,因为 Roo 为我做了它,但现在我将所有内容都转移到 JSF。
There is a Velocity plugin for Tiles 2.2 so you can use both - with velocity you will access context and build your bricks dynamically like with JSP and tiles will combine your website bricks together. However Tiles is not allowing to do many thigns (at least I haven't discovered them yet) and its documentation is very old and bad compared to for example Spring or JSF one. So you can consider using different technology instead.
I have Tiles references in my currect project because Roo did it for me but right now I'm moving everything to JSF.
两者都用。 Tiles 和 Velocity 集成得很好,可以解决不同的问题。您可以使用 Velocity 的 #include 和 #parse 指令做一些类似 Tiles 的事情,但 Tiles 在组合方面做得更好。
Use both. Tiles and Velocity integrate very well and solve different problems. You can do some Tiles-ish stuff with Velocity's #include and #parse directives, but Tiles does that composition stuff better.