How to append hash tables in velocity template?

后端 未结 1 1044
予麋鹿
予麋鹿 2020-12-22 00:42

I tried to append two hash tables in velocity.

#foreach($dun1 in $dotcontent.pull(\"+structureName:Checnas +(conhost:fe1d98e8-9699-4f3f-abf5-a6c0afc8ab47 con         


        
相关标签:
1条回答
  • 2020-12-22 01:08

    Your code currently is over writing $foo each time and hence you are just getting the last value. You can use lists in velocity to achieve this. This might work:

    #set($listOfMnames=[])
    #set($listOfSubNames=[])
    
    #foreach($dun1 in $dotcontent.pull("+structureName:Checnas +(conhost:fe1d98e8-9699-4f3f-abf5-a6c0afc8ab47 conhost:SYSTEM_HOST)",10,"modDate desc"))
    #set($foo=$listOfMnames.add($!{dun1.mname}))
    #set($foo=$listOfSubNames.add($!{dun1.subname}))
    #end
    

    This way, you will end up with two lists 'listOfMnames' and 'listOfSubNames', both fully populated. You can later iterate through them to print/utilise their values.

    This link will be helpful and tell you the purpose of using $foo which is not being used and just being assigned. Alternatively, you can also use velocity maps with proper key/val pairs but be sure to declare it before the loop begins.

    0 讨论(0)
提交回复
热议问题