跟freemarker差不多,不错的东西.
1 配置
把velocity的toolbox.xml放到web-inf下,把velocity.properties放到web-inf下
2 跟spring整合
<servlet>
<servlet-name>velocity</servlet-name>
<servlet-class>
org.apache.velocity.tools.view.servlet.VelocityViewServlet
</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/toolbox.xml</param-value>
</init-param>
<init-param>
<param-name>org.apache.velocity.properties</param-name>
<param-value>/WEB-INF/velocity.properties</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<!-- Map *.vm files to Velocity -->
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
3 常用的用法
#if($userinfo.hasPermission(1))
....
#end
<input type="text" name="roleName" maxlength="15" value="$!role.getRoleName()" class="inputStyle" disabled>
#foreach($fj in $fjList)
<tr height=25>
<td align=left> <a href="..$!fj.getPath()$!fj.getSite()/$!fj.getFileName()" target="RithtFrame">$!fj.getTitle()</a></td>
</tr>
#end
#set ($i=1)
#foreach ($role in $page.getList())
<td >$!i</td>
....
#set ($i=$i+1)
#end