【发布时间】:2021-06-14 05:21:30
【问题描述】:
我在弄清楚如何迁移我的代码以使用 org.stringtemplate.v4 时遇到了一些麻烦。我在 src/main/resources 下的“模板”文件夹中有一个模板文件。没什么好看的。我只需要加载模板,设置一些属性,然后在我的 html 响应中传递它。问题是,模板被捆绑到部署的 jar 中,这意味着我无法进行正常的类路径查找。通常在这种情况下,我会使用 InputStream,但我找不到任何使用 ST 和 STGroup 的可用构造函数的方法。有谁知道如何做到这一点?有没有更简单的方法我只是忽略?
我的代码如下所示:
STGroup group = new STGroupDir("templates");
ST template = group.getInstanceOf("smartSubmitResponse");
template.add("errors", results.exceptions.asMap());
template.add("plannedDates", results.plannedDates);
return Response.status(Response.Status.OK).header("smartSubmitFileUrl", url)
.header("errors", errorHeaders.toString()).entity(template.toString()).build();
目前,由于模板设置不正确,因此失败并出现空指针异常。
【问题讨论】:
标签: java maven wildfly stringtemplate-4