gpt4 book ai didi

java - 将列表传递给 freemarker

转载 作者:行者123 更新时间:2023-11-30 04:54:40 24 4
gpt4 key购买 nike

Java 文件

for(..){
java.util.List opslist = new ArrayList();
opr.setOperationName(operation.getName()); //gets operation name (iterate and get n no of names) sets it to opr
System.out.println(opr.getOperationName());//gets all the set values n prints it(jus to chack that all values r getting set)
opslist.add(opr.getOperationName());//putting those valies into a list
datamodel.put("opslist", opslist.toArray(new String[]{}));//putting it into a hash map with key as opslist and value as opslist object
}

Freemarker 模板

<#list opslist as x> //read the values from the key "opslist" (gets only one value)
${x} //print values one by one(it prints only one value) </#list>

java文件的输出是

get
set
value
usage

Freemarket 模板的输出为

usage

为什么只打印最后一个值?
有人可以告诉我在 freemarker 模板中执行操作的正确方法吗?

最佳答案

看起来您正在为列表中的每个元素创建一个新的 opslist。这样只有最后一个元素被传递给 freemarker。只需将 List opslist = new ArrayList();在for循环前面

关于java - 将列表传递给 freemarker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8925422/

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