在freemarker中重复一个字符串n次

Sak*_*iai 1 freemarker

我正在寻找一种简洁的方法来将字符串重复n次,其中n是一个变量。我在文档中找不到能做到这一点的好方法。

Jas*_*ies 5

您可以简单地使用list迭代范围

<#assign n = 5>
<#list 0..<n as i>hello</#list>
Run Code Online (Sandbox Code Playgroud)

或作为宏:

<#macro repeat input times>
<#list 0..<times as i>${input}</#list>
</#macro>

<@repeat input="hello" times=5/>
Run Code Online (Sandbox Code Playgroud)