Velocity Seventh Application Example----Assignment in a template
2 Create a context Objectvelocitycontext context = Newvelocitycontext ();//3 Add you data object to this CONTEXTCONTEXT.P UT ("name", "Old Bi");//4 Choose a templatetemplate template =velocity.gettemplate ("TEMPLATE7.VM");//5 Merge the template and You data toproduce the outputstringwriter SW = new StringWriter (); Template.merge (context, SW); Sw.flush (); System.out.println (Sw.tostring ());
Template
Array Assignment
#set ($ints =["First", "second", "third"]) #foreach ($entryin $ints) $entry #end=== #set ($ints =[1..10]) #foreach ($int in $ints) $ int#end===${name}=============== #set ($name = "banner") $name = = = #set ($condition =true) #set ($condition =false) #if ($ Condition
Was founded
#else
Not established
#end
====
This is the velocity of the seventh application example----in the template to assign the content, more relevant content please topic.alibabacloud.com (www.php.cn)!