【问题标题】:Smart-like template engine for java? [closed]java的类似智能的模板引擎? [关闭]
【发布时间】:2010-02-08 14:16:16
【问题描述】:

有没有类似Smart的模板引擎(开源)?我想让用户更容易地用 HTML 设计他们的模板然后使用它,smarty-template 真的很适合。 JTPL 与我正在寻找的示例很接近,但我希望模板中的“foreach”部分也能够让用户自定义结果页面。越轻越好!

【问题讨论】:

  • 另外,检查 Java Server Faces(或 Pages),这正是您想要的。

标签: java templates open-source


【解决方案1】:

Velocity 是一个不错的轻量级模板引擎。

【讨论】:

    【解决方案2】:

    Freemarker 也不错。与 Velocity 非常相似,添加了一些不错的功能。

    【讨论】:

      【解决方案3】:

      Rythm 是一个强类型 Java 模板引擎,使用类似于 Razor 的语法,具有高性能(比 Velocity 和 FM 快 2 到 3 倍)。它提供了一种非常轻量级的字符串插值方式:

      String result = Rythm.render("hello @who!", "world");
      

      这种简单性使 Rythm 在许多情况下成为 String.format() 的良好替代品。请注意,Rythm.renderString.format 快 2 倍

      综合模板可以使用同一个接口传入文件名:

      Map<String, Object> args = new HashMap<String, Object>();
      args.put("who", "world");
      ...
      String result = Rythm.render("myTemplate.html", args);
      

      Rythm 具有非常丰富的特性集,包括 java 流控制(if-else、for 循环、集合迭代)、模板继承、外部和内部标签创建和调用、缓存、Java 方法扩展、空间压缩、html 转义等。的功能在http://play-rythm-demo.appspot.com/ 进行了演示。 (是的,该演示是使用 Play!Framework 和 Rythm 模板引擎编写的,并且在 GAE 上运行!)

      在 Rythm 引擎上创建了 Play!Framework 插件,您可以从那里找到有关如何使用 Rythm 的文档:http://www.playframework.org/modules/rythm

      你可以从https://github.com/greenlaw110/rythm/downloads下载Rythm

      还有一个基于Rythm Engine创建的Spring MVC插件:https://github.com/lawrence0819/spring-web-rythm-template

      【讨论】:

        【解决方案4】:

        StringTemplate 是一个流行的轻量级 Java 模板引擎。另外,请在generating web pages with StringTemplate 上查看这些说明。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-12-03
          • 1970-01-01
          • 2011-02-28
          • 2020-03-04
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多