简体   繁体   English

Freemarker无法访问对象字段

[英]Freemarker can't access object field

I am struggling with a Freemarker weird issue. 我正在努力解决Freemarker怪异的问题。

<#list fieldMap?keys as key> 
    ${fieldMap[key]}

    ${fieldMap[key].name}

</#list> 

The console is 控制台是

    GeneratorField{name=expenseType, fieldType=String}

    FreeMarker template error:
The following has evaluated to null or missing:
==> fieldMap[key].name  [in template "ftl/form.ftl" at line 6, column 7]

As you can see, the first line is outputting the name of GeneratorField object, but why the second command failed ? 如您所见,第一行输出的是GeneratorField对象的名称,但是为什么第二条命令失败?

I am using Freemarker 2.3.20 我正在使用Freemarker 2.3.20

Thanks 谢谢

If fieldMap is a class in JAVA then there will be getters in that JAVA class to expose the field name for access, ie, you can create a public function called getName() in that class and then access the same function in your ftl file. 如果fieldMap是JAVA中的一个类,则该JAVA类中将有getter公开要访问的字段名称 ,即,您可以在该类中创建一个名为getName()的公共函数,然后在ftl文件中访问该函数。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM