springmvc-servlet.xml配置
<!-- Velocity --> <bean id="velocityViewResolver" class = "org.springframework.web.servlet.view.velocity.VelocityViewResolver"> <property name="order" value="0" /> <property name="contentType" value="text/html;charset=UTF-8" /> <property name="requestContextAttribute" value="req"/> </bean> <!-- Velocity --> <bean id="velocityConfig" class = "org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="configLocation" value="/WEB-INF/velocity.properties"/> <property name="resourceLoaderPath" value="/" /> </bean> <!-- FreeMarker --> <bean id="freeMarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="order" value="0" /> <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/> </bean> <!-- FreeMarker--> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="configLocation" value="/WEB-INF/freemarker.properties"/> <property name="templateLoaderPath" value="/WEB-INF/ftl/"/> <property name="freemarkerVariables"> <map> <entry key="xml_escape" value-ref="fmXmlEscape"/> </map> </property> </bean> <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"></property> <property name="order" value="1" /> </bean> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> <property name="definitions"> <list> <value>classpath:layout.xml</value> </list> </property> </bean> <!-- 定義JSP文件的位置 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/"/> <property name="suffix" value=".jsp"/> <property name="order" value="1" /> </bean>
注意:關鍵點 <property name="order" value="1" />配置 0,1,2,3,4,5,6......首先從0開始解析,依次往下,jsp的一定要放到最後,不然找到返回頁面直接返回到404頁面
了,不會去其他頁面匹配了,或者吧jsp的order設置到最高,這是個坑,或者自己寫解析器進行解析。就是這麼easy