Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the iterated output in the same line?

Tags:

freemarker

I want to generate some java code using freemarker, that is to generate parameters for a method.Say I have a method named doIt, which needs some parameter name and their class names, I will give the template a param named paramList.I define a macro directive , iterate the parameters list,but consequently each parameter occupies a row. My template code is as below:

<#macro paramList plist>
   <#if plist??>
       <#list plist as p>
           ${p.javaType?substring(2)} ${p.name} <#if p_has_next>, </#if>
       </#list>
   </#if>
</#macro>
doIt(<@paramList plist=params/>)

The running result is :

doIt(           int end , 
           String endDate , 
           String evtCode , 
           int evtNo , 
           String giftCode , 
           int start , 
           String startDate 
)

How to make all the parameters output appear in the same row. I know I can write the list directive logic in the same row to avoid line breaking ,but if there are other logic too, it will get too long to read and understand after a while. The format I want is :

doIt(int end , String endDate, String evtCode , int evtNo , String giftCode , int start , String startDate)
like image 298
user1231111 Avatar asked Feb 24 '12 15:02

user1231111


1 Answers

Put a <#t> after the innermost </#if>. (See http://freemarker.org/docs/ref_directive_t.html#ref.directive.t)

like image 52
ddekany Avatar answered Sep 29 '22 03:09

ddekany