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)
Put a <#t>
after the innermost </#if>
. (See http://freemarker.org/docs/ref_directive_t.html#ref.directive.t)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With