Java视图模板库
我需要一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 Velocity 可能适合您的情况
I think Velocity can be suitable in your case
除了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.