SpringMVC整合velocity+toolbox.xml(Java工具類)
1.SpringMVC視圖的配置
<!-- 配置視圖的顯示 -->
<bean id="inliantuoviewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="cache" value="true"/>
<property name="toolboxConfigLocation" value="/WEB-INF/classes/config/spring/common/toolbox.xml"/>
<!--是否使用spring對宏定義的支持-->
<property name="exposeSpringMacroHelpers" value="true"/>
<!--是否開放request屬性-->
<property name="exposeRequestAttributes" value="true"/>
<!--request屬性引用名稱-->
<property name="requestContextAttribute" value="rc"/>
<!-- 視圖文件的前綴,即存放的路徑 -->
<property name="prefix" value=""/>
<!-- 視圖文件的後綴名 -->
<property name="suffix" value=".vm"/>
<!-- <property name="viewClass" value="com.liantuo.international.utils.VelocityToolbox20View"/> -->
<property name="contentType">
<value>text/html; charset=UTF-8</value>
</property>
</bean>
(2)toolbox.xml的配置
<?xml version="1.0"?>
<toolbox>
<tool>
<key>dateFormatter</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.DateTool</class>
</tool>
<tool>
<key>numberFormatter</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.NumberTool</class>
</tool>
<tool>
<key>mathTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.MathTool</class>
</tool>
<tool>
<key>dateUtils</key>
<scope>application</scope>
<class>com.liantuo.util.DateUtil</class>
</tool>
<tool>
<key>numberUtils</key>
<scope>application</scope>
<class>com.liantuo.util.NumberUtils</class>
</tool>
<tool>
<key>stringUtils</key>
<scope>application</scope>
<class>com.liantuo.util.StringUtils</class>
</tool>
<tool>
<key>number</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.NumberTool</class>
<parameter name="format" value="#0.0"/>
</tool>
</toolbox>
(3) 頁面調用
$!number.format("#0.00", 5467.9876)
(4) 效果展示