【问题标题】:Velocity Tool XmlTool速度工具 XmlTool
【发布时间】:2016-10-07 06:50:31
【问题描述】:

我正在尝试使用 XmlTool 解析 XML 文件,以便能够使用 Velocity 模板中的数据。

但是,关于它的文档都很差,并没有真正提供我需要的信息。

文档位于:https://velocity.apache.org/tools/devel/apidocs/org/apache/velocity/tools/generic/XmlTool.html

我已经试过了:

VelocityContext context = new VelocityContext(page);

EasyFactoryConfiguration config = new EasyFactoryConfiguration();
                config.toolbox("application")
                    .tool("org.apache.velocity.tools.generic.XmlTool")
                    .property("safeMode", false)
                    .property("key", "foo")
                    .property("file", xmlFilePath);

ToolboxFactory factory = config.createFactory();

template = Velocity.getTemplate(page.get("template-file"));
template.merge(context, write);
return write.toString();

但这不起作用。 如何使数据真正进入我的模板?我觉得我错过了很多步骤,但找不到我需要的信息!

【问题讨论】:

  • 错误是什么?你的模板是什么样的?

标签: java velocity velocity-tools


【解决方案1】:

嗯,我的那个聪明的同事一开始就应该这样做。

XmlTool tool = new XmlTool();
tool = tool.read(dataFile.getAbsolutePath());
context.put("foo", tool);

【讨论】:

    猜你喜欢
    • 2014-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    相关资源
    最近更新 更多