Currently I am doing a project which involve Nvelocity template, however, I need use advance foreach, I could find the reference, just I could not figure out how does it works,reference link

#foreach($l in $markPoint)hardcodetext($l)#end

however, I need add "," between items,hardcode will left one after last item, which I don't want, any helps?

有帮助吗?

解决方案

The NVelocity special foreach looping directives are just nested sections inside the foreach directive, which you define bits of the template. Following is an example of the basic structure for putting a comma between each item:

#foreach($i in [1..5])
#between
,
#each
$i
#end

Because the nested directives cannot contain anything else on the same line they and because of the newline that is included at the end they can be a bit of a pain if you care about extra whitespace appearing, so if you want the output to look exactly like "1,2,3,4,5" without any whitespace you'll need to remove some of the newlines between things like follows:

#foreach($i in [1..5])#between
,#each
${i}#end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top