简体   繁体   English

速度与Apache Tiles

[英]Velocity vs Apache Tiles

What's better? 什么更好? We are going to start a new web project and it's a question which technology to choose. 我们将开始一个新的Web项目,这是一个选择哪种技术的问题。 Project includes Spring MVC + WebFlow. 项目包括Spring MVC + WebFlow。 Any good/bad experience in support, extending, performance? 在支持,扩展和绩效方面有任何好的/坏的经验吗?

Thank you. 谢谢。

Velocity and Tiles are two different beasts — Tiles is a layout engine and Velocity is a template engine. Velocity和Tiles是两种不同的野兽--Tiles是布局引擎,Velocity是模板引擎。 They do not intersect anywhere in terms of functionality. 它们在功能方面不会交叉。

From your question I can guess you probably won't be using JSP. 从你的问题我猜你可能不会使用JSP。 That's a smart move. 这是一个聪明的举动。 Velocity is one of the template engines out there and it does an absolutely splendid job. Velocity是那里的模板引擎之一,它做了绝对出色的工作。

And if you choose to follow the template engine route for your view, then check out commentit . 如果您选择按照模板引擎路线查看视图,请查看commentit It's a small, simple and fast layout engine I created. 这是我创建的一个小巧,简单,快速的布局引擎。 It might serve your purpose perfectly. 它可能完美地满足您的目的。

How do you want compare Tiles with Velocity? 你想怎么比较Tiles和Velocity? - Tiles is a way to compose page fragments, while Veleocity is a more complete template engine, better comparable with JSP than Tiles. - Tiles是一种组合页面片段的方法,而Veleocity是一个更完整的模板引擎,与JSP相比,可以比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. 无论如何:我使用Spring MVC和Tiles和JSP:它工作得很好,节省了很多时间(仅仅使用JSP或者使用Sitemash的JSP),我没有注意到任何性能问题。 (But the web application was never used under high load.) (但Web应用程序从未在高负载下使用过。)

Use Tiles if you have some seperate HTML files that you want to bring together in a Template (ie 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). 如果你想在模板中加入一些单独的HTML文件,请使用Tiles (即你有一个Header,Footer,Sidebar的单独页面,你想把它们组合在一起并以类似报纸的格式显示它们)。

Use Velocity if you want to bring dynamic content across from a Java backend and inject those values into a full HTML page (ie you have a HTML table to display a selection of Cars, and all of your cars are stored in a Database. Using JPA , you could get that Car data out of the database, and into a List<Car> maintained in an EJB Bean, Spring @Component , or similar. Then, using Velocity, you can store that information as the bucket item inside a Map , and use the VTL mark-up to refer to the key value items in the Map so that they can be rendered as part of the HTML response. 如果要从Java后端引入动态内容并将这些值注入完整的HTML页面(即,您有一个HTML表来显示一系列Cars,并且所有汽车都存储在数据库中),请使用Velocity 。使用JPA ,你可以从数据库中获取Car数据,并将其从EJB Bean, Spring @Component或类似物中维护的List<Car>中获取。然后,使用Velocity,您可以将该信息存储为Map的桶项,并使用VTL标记来引用Map的键值项,以便它们可以作为HTML响应的一部分进行呈现。

To achieve the above, Velocity positions itself as an outright Front Controller Servlet, or is wrapped by another MVC framework (ie Spring MVC provides a View Resolver which wraps the functionality provided by a Velocity Servlet). 为了实现上述目的,Velocity将自己定位为一个彻头彻尾的Front Controller Servlet,或者由另一个MVC框架包装(即Spring MVC提供了一个View Resolver,它包含了Velocity Servlet提供的功能)。

HTML requests are directed to the Velocity Servlet or alternative MVC Framework Servlet via web.xml configuration. HTML请求通过web.xml配置定向到Velocity Servlet或备用MVC框架Servlet。 As part of the servlet response, your pre-baked HTML view, complete with Velocity VTL mark-up, is enriched with Map data. 作为servlet响应的一部分,预先烘焙的HTML视图(包含Velocity VTL标记)可以使用Map数据进行丰富。

Effectively, and in summary: 有效地,总结:

Velocity competes in the same space as JSP. Velocity在与JSP相同的空间中竞争。

Tiles is more akin to page transclusion. Tiles更类似于页面转换。 In the PHP space, Smarty is a popular cousin. 在PHP空间中,Smarty是一个受欢迎的堂兄。

You don't choose between them, but very well could use both . 你不要在它们之间做出选择,但很好地可以同时使用它们

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. Tiles 2.2有一个Velocity插件,因此您可以使用两者 - 使用velocity,您将访问上下文并动态构建您的砖块,就像使用JSP一样,tile会将您的网站砖块组合在一起。 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. 然而,Tiles不允许做很多东西(至少我还没有发现它们),并且与例如Spring或JSF相比,它的文档非常陈旧。 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引用,因为Roo为我做了,但是现在我将所有内容都移到了JSF。

Use both. 使用两者。 Tiles and Velocity integrate very well and solve different problems. Tiles和Velocity非常好地集成并解决了不同的问题。 You can do some Tiles-ish stuff with Velocity's #include and #parse directives, but Tiles does that composition stuff better. 你可以用Velocity的#include和#parse指令来做一些Tiles-ish的东西,但是Tiles做的更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM