java 使用 Spring/Hibernate 时 Freemarker 的替代品?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12433506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:52:21  来源:igfitidea点击:

Alternatives to Freemarker when using Spring/Hibernate?

javaajaxspringweb-applicationsfreemarker

提问by egervari

What are some modern, more-productive alternatives to Freemarker as view technology for rich web-applications using Spring? Is Spring MVC/Freemarker still one of the best combinations, or are there others?

作为使用 Spring 的富 Web 应用程序的视图技术,有哪些现代的、更高效的 Freemarker 替代方案?Spring MVC/Freemarker 仍然是最好的组合之一,还是还有其他组合?

The application I have to build is small, but complex that will likely require a lot of custom javascript as all of the controls and ui is very non-standard (it's not really a business application). Blizzard's gaming websites like for Diablo 3 is an example of what I'm trying to do.

我必须构建的应用程序很小,但很复杂,可能需要大量自定义 javascript,因为所有控件和 ui 都非常不标准(它不是真正的业务应用程序)。暴雪的游戏网站,比如暗黑破坏神 3,就是我想要做的一个例子。

Is this combination still the best to suite my needs, or are there other technologies I should take a look at?

这种组合是否仍然最能满足我的需求,或者我应该看看其他技术吗?

Thanks

谢谢

回答by ?ukasz R?anek

There are several good and well established template engines on the market. Most of them play nice with Spring.

市场上有几种良好且完善的模板引擎。它们中的大多数与 Spring 搭配得很好。

  • Velocity- a classic and one of the most popular template engines out there. Quite good, quite flexible, ugly syntax but good Eclipse plugin.
  • Thymeleaf- one of the most feature rich and flexible template engine on the market. Performance is good, although not ground breaking. My personal choice for most of the projects.
  • String Template- really good performance, quite hard to use. Very flexible, thought...
  • MVEL- seems to be really, really fast and quite feature-rich. For me it was to complex and quite hard to use in a project with junior devs.
  • Rhythm- from a Play framework to Java, nice and very flexible. Razor syntax is great. Rhythm is really fast, very flexible and nice to use. Another personal choice for my projects, next to Thymeleaf. There is a nice articleon how to use this engine in Java.
  • httl- small, easy to use, not that fast but still good enough. Quite flexible but not that feature rich.
  • Trimou- another fairly new kid on the block. Looks decent, uses Mustache templating syntax and is fairly easy to use. But for my taste a bit too simplistic and missing some features.
  • Rocker- apparently a fairly new development, actively maintained and extended at this time. I like it, it has a nice idea for the syntax but it is nothing that resembles other syntaxes. A lot of simple features, missing some advanced ones IMHO. Very performant according to a test we just made.
  • Pebble- we used it for a couple of different purposes and it proved rather simple to use with a decent syntax inspired by Twig from PHP world. Performance is really good, one of the fastest we tried.
  • Velocity- 经典且最受欢迎的模板引擎之一。相当好,相当灵活,语法丑陋,但很好的 Eclipse 插件。
  • Thymeleaf- 市场上功能最丰富、最灵活的模板引擎之一。性能不错,虽然不是开创性的。我个人对大多数项目的选择。
  • 字符串模板- 性能非常好,很难使用。非常灵活,思想...
  • MVEL- 似乎非常非常快并且功能非常丰富。对我来说,在初级开发人员的项目中使用它很复杂并且很难使用。
  • Rhythm- 从 Play 框架到 Java,很好而且非常灵活。Razor 语法很棒。节奏非常快,非常灵活且易于使用。我的项目的另一个个人选择,在 Thymeleaf 旁边。有一篇关于如何在 Java 中使用这个引擎的好文章
  • httl- 小巧,易于使用,速度不快但仍然足够好。相当灵活,但功能不是很丰富。
  • Trimou- 这个街区的另一个相当新的孩子。看起来不错,使用 Mustache 模板语法并且相当容易使用。但对我来说有点过于简单化,缺少一些功能。
  • Rocker- 显然是一个相当新的发展,此时积极维护和扩展。我喜欢它,它对语法有一个很好的想法,但它与其他语法没有什么相似之处。很多简单的功能,恕我直言,缺少一些高级功能。根据我们刚刚进行的测试,性能非常好。
  • Pebble- 我们将它用于几个不同的目的,事实证明它使用起来相当简单,它的语法受到来自 PHP 世界的 Twig 的启发。性能非常好,是我们尝试过的最快的之一。


Performance wise, according to our tests, in order from the slowest:

根据我们的测试,性能方面,从最慢的顺序:

  1. Thymeleaf
  2. Freemarker
  3. Velocity
  4. Trimou
  5. Mustache
  6. Pebble
  7. Rocker
  1. 百里香叶
  2. 自由标记
  3. 速度
  4. 特里穆
  5. 胡子
  6. 卵石
  7. 摇杆

Your mileage may vary!...

你的旅费可能会改变!...



There is a nice comparison of few of those(quite old article). Also a nice tutorial on how to use some of them by Baeldung

几个很好的比较(相当旧的文章)。也是Baeldung关于如何使用其中一些的一个很好的教程

There are plenty of template engines out there. Check this directoryif you need more...

那里有很多模板引擎。如果您需要更多,请检查此目录...