gpt4 book ai didi

java - 使用 FieldMethodizer 访问静态文件打印 "Could not add x for field methodizing: x"

转载 作者:行者123 更新时间:2023-12-02 02:47:50 24 4
gpt4 key购买 nike

当我尝试在模板中使用速度的 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

最佳答案

使用FieldMethodizer时,您需要添加将完整类名建模为com.package.Path

context.put("runtime", new FieldMethodizer( "org.apache.velocity.runtime.Runtime" ));

然后在模板中使用$WebPath.Web

and then in your template, you can access any of your static fields in this way :

$runtime.COUNTER_NAME

关于java - 使用 FieldMethodizer 访问静态文件打印 "Could not add x for field methodizing: x",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57132108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com