freemarker 中的连接字符串

Concatenation strings in freemarker

如何在 freemarker 中连接字符串?

这行不通。

    <#function foo input>
<#local str="Hello ">
${str} = ${str} + ${" world"}

<#return str>
</#function>

${foo("a")}

在线测评人:
http://freemarker-online.kenshoo.com/

编辑:为了清楚起见,我需要将它与变量一起使用,以便能够编写这样的内容。


public String sayHello() {return "Hello";}
public String sayWorld() {return "world"};
public String sayPeople() {return "people";}

public void main() { 
 String str = "";
 str += sayHello();
 str += "";
 str += sayWorld();
 str += "";
 str += sayPeople();

 return str;
}

喜欢<#return "Hello " + input + "!">,或<#return "Hello ${input}!">。如果您尝试在 #function 内打印输出(与 #macro 内相反),它将被忽略。

编辑:与添加的 Java 示例类似:

<#function concatDemo>
 <#local str = "">
 <#local str += sayHello()>
 <#local str += " ">
 <#local str += sayWorld()>
 <#local str += "!">
 <#return str>
</#function>

<#function sayHello><#return "Hello"></#function>
<#function sayWorld><#return "World"></#function>

${concatDemo()}