简体   繁体   English

最快的Java Web模板语言

[英]Fastest Java web templating language

I'm about to start in on a new Spring MVC project, and I'm examining the various options for the view. 我即将开始一个新的Spring MVC项目,我正在研究视图的各种选项。 I've never been a fan of JSP, and I've run into JSP-related performance problems in the past, so I was looking through the other options. 我从来都不是JSP的粉丝,过去我遇到过与JSP相关的性能问题,所以我正在研究其他选项。 I'm hoping that somewhere somebody's taken a census of the various options (maybe it'll have to be me) and pronounced which ones are quick, or at least which options there are. 我希望在某个地方有人对各种选项进行普查(也许它必须是我),并宣布哪些是快速的,或者至少有哪些选项。 Here are the choices I've thought of, ordered from obvious to bizarre: 以下是我想到的选择,从明显到奇怪的排序:

  • JSP, JSTL JSP,JSTL
  • Velocity 速度
  • FreeMarker FreeMarker的
  • GSP (Groovy JSP) GSP(Groovy JSP)
  • ERB powered by IronRuby or some such craziness ERB由IronRuby或一些这样的疯狂驱动
  • Tea

Any suggestions, personal preferences, or other good options for the list? 列表的任何建议,个人偏好或其他好的选择?

StringTemplate - fast, simple and helps enforce MVC separation of concerns. StringTemplate - 快速,简单并有助于强制关注MVC分离。 Last I checked, Spring Web MVC doesn't provide a View class for it, but I was able to easily create a custom one . 最后我查了一下,Spring Web MVC没有为它提供View类,但我能够轻松创建一个自定义类

While I would probably go with FreeMarker or Velocity myself, I am surprised at what you call 虽然我可能会自己选择FreeMarker或Velocity,但我对你所说的内容感到惊讶

JSP-related performance problems JSP相关的性能问题

Of all these possible solutions, JSP is obviously the best-performing. 在所有这些可能的解决方案中,JSP显然是性能最佳的。 After all, JSP pages are compiled to Servlet classes and executed from byte code whereas all the other technologies you mentioned are interpreted. 毕竟,JSP页面被编译为Servlet类并从字节代码执行,而您提到的所有其他技术都被解释。

If you have performance problems, either optimize your JSP code or use a JSP compiler like JSPC to pre-compile your JSP pages (perhaps with maven, using the JSPC-maven-plugin ). 如果遇到性能问题,可以优化JSP代码或使用JSP编译器(如JSPC)预编译JSP页面(可能使用maven,使用JSPC-maven-plugin )。

I prefer Velocity these days. 这些天我更喜欢Velocity。 The performance is fine. 表现很好。 I like the natural way it decouples the template and the data. 我喜欢它解耦模板和数据的自然方式。

I used to use Velocity. 我曾经使用过Velocity。 The project stagnated a bit and had some known issues, so switched over to Freemarker. 该项目停滞不前并有一些已知问题,因此切换到Freemarker。 I believe (don't quote me) Freemarker came about because Velocity lost momentum. 我相信(不要引用我)Freemarker的出现是因为Velocity失去了动力。 No pun intended. 没有双关语。

Since then Velocity has become active again, at least for a while. 从那以后,Velocity再次活跃起来,至少有一段时间了。 I prefer Freemarker right now, but either of these two work well. 我现在更喜欢Freemarker,但这两个中的任何一个都很好用。 I'd go with whichever one plugs in easier to Spring MVC. 我会选择更容易进入Spring MVC的插件。

I agree with Sean Patrick Floyd that JSP should be realy fast. 我同意肖恩·帕特里克·弗洛伊德的观点,认为JSP应该非常快。 In most cases even faster then the other Template engines, even if they are cached. 在大多数情况下,甚至比其他模板引擎更快,即使它们被缓存。

If you realy run in an JSP related performance issue than I belive you should rethink the way how you use JSP. 如果您真的遇到与JSP相关的JSP相关性能问题,那么您应该重新思考如何使用JSP。

And at least, if you have a hot spot which causes the performance issue, than you can build this (hopeflully) small pice by hand (StringBuilder). 至少,如果你有一个导致性能问题的热点,那么你可以手工构建这个(hopeflully)小pice(StringBuilder)。

So to wrapp this up: I belive JSP is the fasted one (except doing it by hand), but on the other hand, you must have a very special use case to run in a perfomace issue with any of the major template engienes you mentioned. 所以要解决这个问题:我相信JSP是禁食的(除了手工操作),但另一方面,你必须有一个非常特殊的用例来运行你提到的任何主要模板工程的性能问题。

You should try MVEL . 你应该试试MVEL It is faster than anything i know (incl. StringTemplate), really powerful and feels like scripting in plain java. 它比我知道的任何东西都快(包括StringTemplate),非常强大,感觉就像在普通的java中编写脚本。

<p>
   @foreach{index : alphabetical}
     <a href="@{index.uri}">@{index.description}</a>
   @end{}
</p>

or 要么

<a href="@{ua.pageURI}">
   @{org.apache.commons.lang.StringEscapeUtils.escapeHtml(ua.name)}
</a>

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

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