springmvc velocity 配置

<span style="white-space:pre">	</span><!-- 配置velocity引擎 -->
 	<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
		<!-- 模板存放的路徑 -->
		<property name="resourceLoaderPath" value="/WEB-INF/vm/" />
		<property name="velocityProperties">
			<props>
				<!-- 指定模板引擎進行模板處理的編碼 -->
				<prop key="input.encoding">gbk</prop>
				<!-- 指定輸出流的編碼 -->
				<prop key="output.encoding">gbk</prop>
				<!-- 設置foreach自增屬性及開始值 -->
				<prop key="directive.foreach.counter.name">loopCounter</prop>   
        		<prop key="directive.foreach.counter.initial.value">0</prop>
			</props>
		</property>
	</bean>

	<!-- 配置解析Velocity視圖  -->
	<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
		<!-- 視圖文件的前綴後綴 -->
		<property name="prefix" value="/" />
		<property name="suffix" value=".vm" />
		<!-- 請求編碼格式 -->
		<property name="contentType" value="text/html;charset=gbk" />
		<!-- 暴露session、request對象在頁面直接使用 -->
		<property name="exposeSessionAttributes" value="true" />
		<property name="exposeRequestAttributes" value="true" />
		<!--  配置工具類 -->
		<!-- VelocityToolboxView 類只支持1.X的velocitytools -->
		<property name="toolboxConfigLocation" value="/WEB-INF/classes/tool.xml"/>
		<property name="viewClass" value="org.springframework.web.servlet.view.velocity.VelocityToolboxView"/>
	</bean>


tool.xml 內容
	
<?xml version="1.0"?>

<toolbox>
	<tool>
		<key>dateTool</key>
		<scope>application</scope>
		<class>com.shimne.utils.DateTool</class>
	</tool>

	<tool>
		<key>numberTool</key>
		<scope>application</scope>
		<class>com.shimne.utils.NumberTool</class>
	</tool>
</toolbox>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章