Java视图模板库

发布于 2024-12-20 05:01:33 字数 552 浏览 4 评论 0原文

我需要一个 Java 库,允许我定义自己的标签/命令,然后根据给定的数据模型创建 html 输出。

在示例中,我希望库能够处理这种情况:

String template = "<name>key1</name><image>key1</image>"
map.put("key1", imageObject);
String html = parser.parse(template, map);
html == "<i>An Image</i><img src='image.jpg'/>"

因此基本功能是基于自定义标记生成html(例如) -每个标签都会生成不同的输出。

name 将打印字符串,而 image 将放置图像。 imageObject 具有解析库可以访问的适当字段。

亲切的问候,

奎奎格

I need a Java library allowing me to define my own tags / commands and then creating html output based on a given data-model.

In example I'd like the library to handle such a situation:

String template = "<name>key1</name><image>key1</image>"
map.put("key1", imageObject);
String html = parser.parse(template, map);
html == "<i>An Image</i><img src='image.jpg'/>"

So the basic functionality would be to generate html based on the custom tag (e.g. <name>) - each tag would generate different output.

I.e. name would print a string, whereas image would place an image. The imageObject has appropriate fields that the parsing library can reach.

Kind regards,

Queequeg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝海 2024-12-27 05:01:33

我认为 Velocity 可能适合您的情况

I think Velocity can be suitable in your case

¢蛋碎的人ぎ生 2024-12-27 05:01:33

除了Velocity之外,另外两个模板引擎FreeMarker和StringTemplate也值得关注。

有足够的资源来决定使用哪个,但 StringTemplate 可能就足够了。

Except Velocity, it worth looking at another two template engines FreeMarker and StringTemplate.

There is enough resources to take decision which to use, but probably StringTemplate is enough.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文