java FreeMarker:需要哈希值,但已计算为序列

y1aodyip  于 2023-06-20  发布在  Java
关注(0)|答案(1)|浏览(128)

我知道同样的问题已经在这里了。但不幸的是,它并没有帮助我解决我的问题。我在我的FreeMarker模板中有HashSet。我想在视图中显示HashSet的大小。我对此有以下几点:

<td>${repo.getRepoWords().size()}</td>

方法getRepoWords是:

public HashSet getRepoWords() {
     return repoWords;
 }

结果我看到了这个例外
FreeMarker模板错误(DEBUG模式;在生产中使用RETHROW!):对于"."左操作数:需要哈希值,但计算结果为序列( Package 器:f.t. SimpleSequence):==> repo. getRepoWords()[in template "repositories/detail. ftl" at line 24,column 23]----FTL stack trace("~"means nesting-related):- 失败地点:${repo. getRepoWords(). size()}[in template "repositories/detail. ftl" at line 24,column 21]~通过以下方式访问:#nested [in template "layouts/common. ftl" in macro "page" at line 20,column 1]~到达:@www.example.com title ="Г л а в н а я с т р а н и ц а"[in template "repositories/detail. ftl" at line 2,column 1]----Java stack trace(for programmers):c.page[...已打印异常消息;见上文...] at freemarker.core.Dot._eval(Dot.java:48)at freemarker.core. Expression. eval(Expression.java:83)at freemarker.core.MethodCall._eval(MethodCall.java:58)at freemarker.core. Expression. eval(Expression.java:83)at [... Exception message was already printed; see it above ...] at freemarker.core.Dot._eval(Dot.java:48) at freemarker.core.Expression.eval(Expression.java:83) at freemarker.core.MethodCall._eval(MethodCall.java:58) at freemarker.core.Expression.eval(Expression.java:83) at
我可以在FreeMarker模板中对HashSet使用size()方法吗?

x4shl7ld

x4shl7ld1#

我建议你像下面这样使用?size。请检查文档

${repo.repoWords?size}

相关问题