package tony.test; /** *//** * @author Tony * The class should be public, and implement get/set. */ publicclass DoThings ...{ private String name; private String things; public DoThings(String name, String things) ...{ this.name = name; this.things = things; } public String getName() ...{ return name; } publicvoid setName(String name) ...{ this.name = name; } public String getThings() ...{ return things; } publicvoid setThings(String things) ...{ this.things = things; } }
E:/templates/velocity.helloworld.vm(完整路径):
<html> <body> I am the $YOUR_CHARACTERISTIC $YOUR_NAME. <br /><br /> I will $DO_THINGS for $REPEAT_TIME times: <br /><br /> #foreach($EACH_TIME in $ALL_TIMES) $velocityCount. $EACH_TIME.name -- $EACH_TIME.things <br /> #end <br /> #if($YOUR_NAME == "Tony") Best wishes! #else Go to die! #end </body> </html>
生成结果:
<html> <body> I am the old Tony. <br /><br /> I will laugh for 3 times: <br /><br /> 1. Haha -- Giggle <br /> 2. Hehe -- Smile <br /> 3. Kaka -- Die <br /> <br /> Best wishes! </body> </html>