java - 使用 FieldMethodizer 访问静态文件打印“无法为字段方法化添加 x:x”
问题描述
当我尝试FieldMethodizer
在我的模板中使用速度的变量时,它会打印错误。
我正在使用 SparkJava 框架和速度模板引擎。
public static String render(Map<String, Object> model, String templatePath) {
model.put("WebPath", new FieldMethodizer("Path.Web"));
return strictVelocityEngine().render(new ModelAndView(model, templatePath));
}
private static VelocityTemplateEngine strictVelocityEngine() {
VelocityEngine configuredEngine = new VelocityEngine();
configuredEngine.setProperty("runtime.references.strict", true);
configuredEngine.setProperty("resource.loader", "class");
configuredEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
return new VelocityTemplateEngine(configuredEngine);
}
我收到错误
Could not add Path.Web for field methodizing: Path.Web
解决方案
我改行model.put
来model.put("WebPath", new FieldMethodizer(new Path.Web()));
解决这个问题。
推荐阅读
- javascript - 单击时使用 HTML 元素更改 Javascript 变量值 (wavesurfer.js)
- reactjs - 将状态更改为 React 复选框
- azure - 使用最新的 Javascript 片段时如何调用 addTelemetryInitializer?
- haskell - 如何克服 Heroku 上 Haskell 项目的构建时间限制?
- visual-studio - VS2019 - msbuild 未被识别为内部或外部命令
- azure-devops - 当我只配置 CI 分支时,为什么我的 Azure DevOps YAML 构建会在 PR 上触发
- java - 在同步块中为所有线程初始化静态变量,不同步读取
- reactjs - Gatsby 没有生成正确的静态 HTML 文件
- excel - 使用 Excel VBA 在电子邮件正文中以表格形式发送范围
- ruby - Firebase Cloud Function 不再接收来自 ruby 的 Net:HTTP 的调用