Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有非字符串键的freemarker贴图_Java_Freemarker - Fatal编程技术网

Java 具有非字符串键的freemarker贴图

Java 具有非字符串键的freemarker贴图,java,freemarker,Java,Freemarker,我正在尝试使用Freemarker处理Map 我在使用非字符串键时阅读了有关问题的文档: 这就是我的代码 Configuration configuration = new Configuration(Configuration.VERSION_2_3_22); configuration.setClassForTemplateLoading(Main.class.getClass(), "/"); configuration.setAPIBuiltinEnabled(true); Templa

我正在尝试使用Freemarker处理
Map

我在使用非
字符串
键时阅读了有关问题的文档:

这就是我的代码

Configuration configuration = new Configuration(Configuration.VERSION_2_3_22);
configuration.setClassForTemplateLoading(Main.class.getClass(), "/");
configuration.setAPIBuiltinEnabled(true);
Template template = configuration.getTemplate("myTemplate.ftl");

Map<String, Object> templateData = new HashMap<>();
templateData.put("myMap", myMap);

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
template.process(templateData, outputStreamWriter);
有什么想法吗


更新:地图类型为

Map

该映射是从
com.google.common.collect.Table创建的,使用方法
rowMap()



可能的解决方案:如果我使用
,它会起作用。

对我有效。。。我想我们应该看看
myMap
到底是什么。顺便说一句,有几个疏忽,没有一个与这个问题相关:
Main.class.getClass()
应该是
Main.class
,在第二个
#list
的第一个参数之后,您缺少了另一个
?键。是的,我丢失了
?钥匙
刚刚添加,但没有更好的
Main.class
正是我启动代码的类,如果只是针对
classloader
With
Table
rowMap()
它对我仍然有效。那里一定有某种疏忽。比如,
myMap
可能不是
rowMap()
的结果,而是
表本身。(从
Main.class.getClass()
开始,我想说的是,您不需要在它的末尾使用
.getClass()
)我将在github asapWorks上为我发布完整的代码。。。我想我们应该看看
myMap
到底是什么。顺便说一句,有几个疏忽,没有一个与这个问题相关:
Main.class.getClass()
应该是
Main.class
,在第二个
#list
的第一个参数之后,您缺少了另一个
?键。是的,我丢失了
?钥匙
刚刚添加,但没有更好的
Main.class
正是我启动代码的类,如果只是针对
classloader
With
Table
rowMap()
它对我仍然有效。那里一定有某种疏忽。比如,
myMap
可能不是
rowMap()
的结果,而是
表本身。(从
Main.class.getClass()
开始,我想说的是,您不需要在它的末尾使用
.getClass()
)我将在github asapWorks上为我发布完整的代码。。。我想我们应该看看
myMap
到底是什么。顺便说一句,有几个疏忽,没有一个与这个问题相关:
Main.class.getClass()
应该是
Main.class
,在第二个
#list
的第一个参数之后,您缺少了另一个
?键。是的,我丢失了
?钥匙
刚刚添加,但没有更好的
Main.class
正是我启动代码的类,如果只是针对
classloader
With
Table
rowMap()
它对我仍然有效。那里一定有某种疏忽。比如,
myMap
可能不是
rowMap()
的结果,而是
表本身。(从
Main.class.getClass()
开始,我想说的是,您不需要在它的末尾添加
.getClass()
。)我将尽快在github上发布完整的代码
<#list myMap?keys as key>
        <h2>${key}</h2>
        <#list myMap?api.get(key)?keys as key2>
            ${key2}
        </#list>
</#list>
Exception in thread "main" FreeMarker template error:
The following has evaluated to null or missing:
==> myMap?api.get  [in template "template.ftl" at line 196, column 40]