类似于ZPT(属性语言)的Java模板库
我最近一直在 python 中使用 ZPT ,我喜欢模板语言。我一直在寻找与 Java 类似的东西,但找不到我喜欢的东西。最接近的是 FreeMarker。
FreeMarker 和我研究过的其他 Java 模板引擎的问题是它们的 JSP 样式语法允许不符合规范的 XML。我只是想知道是否有一个类似于 Zope 页面模板的 Java 模板引擎,这样它就是一种需要有效 xml 的“属性”语言。
I've been using ZPT in python recently and I love the templating language. I was looking for something similar for Java but couldn't really find anything I liked as well. The closest thing is FreeMarker.
The problem with FreeMarker and the other Java template engines I looked at was their JSP style syntax that allows for non-conforming XML. I was just wondering if there was a Java template engine that is similar to Zope Page Templates such that it's an "attribute" language that requires valid xml.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我认为您正在寻找相当多的模板引擎:
支持有效 html 的其他方法有:
I think think there quite some of the template engines your looking for:
Other approaches supporting valid html are:
FreeMarker 对 AWT 有着严重的依赖。它使得它无法与 Google App Engine 等工具一起使用。
我更喜欢使用 StringTemplate 来满足我所有的 Java 模板需求。它是唯一一个基于Java的模板系统,将逻辑与模板严格分离。
由于您正在生成 XML
另一个乍一看并不明显的解决方案是使用 JAXB。我们这里有一个项目需要生成 XML,我们为输出文件定义了非常明确的 XSD 文件,构建对象并编组它们非常简单且轻松。
FreeMarker has a nasty dependency on AWT. It makes it impossible to use with things like Google App Engine.
I prefer to use StringTemplate for all my Java templating needs. It is the only Java based template system that strictly separates the logic from the template.
Since you are generating XML
Another solution that isn't obvious at first sight is using JAXB. We have a project here that requires us to generate XML, we have very well defined XSD files for the output files, building the objects and marshalling them is super easy and very painless.
您会发现与 Chameleon 最相似的 Java 模板引擎是 Thymeleaf。
The java template engine you will find to be most similar to Chameleon is Thymeleaf.
Distal 用于基于客户端的模板。
There is Distal for client based templating.
据我所知,目前有两个 tal Java 实现的:
There are currently two tal implementations for Java that I know of:
还有 Apache Velocity。尽管它不要求您的模板是有效的 XML。考虑到这个问题,这可能会破坏你的交易。不过,您可能可以通过对核心类的扩展来强制执行该规则。
There is also Apache Velocity. Although it doesn't require that your templates be valid XML. That may be a deal breaker for you given the question. You could likely enforce that rule with extensions to the core classes though.
GXP 怎么样?
还有 LSP 和 xtempore。
What about GXP?
There's also LSP and xtempore.