關於springmvc如何整合freemaker 能夠參考 http://my.oschina.net/bddiudiu/blog/228788 html
可是若是隻是發佈到前端的頁面是須要靜態化 即便用freemaker來生成 後臺的操做部分的頁面仍是用jsp這時候咱們應該怎麼作呢...前端
咱們看一下 springMVC-servlet.xml的配置文件web
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd"> <!-- 啓動Spring MVC的註解功能,完成請求和註解POJO的映射 請求映射--> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" > <property name="messageConverters"> <list> <bean class = "org.springframework.http.converter.StringHttpMessageConverter"> <property name = "supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> </list> </property> </bean> </list> </property> </bean> <!--對web包中的全部類進行掃描,以完成Bean建立和自動依賴注入的功能 --> <context:component-scan base-package="com.youto.controller"/> <mvc:annotation-driven /> <!-- 靜態文件目錄 --> <mvc:resources location="/assets/" mapping="/assets/**" /> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/manager/**"/> <bean class="com.youto.util.ManagerInterceptor" /> </mvc:interceptor> </mvc:interceptors> <!--如下三種視圖配置根據須要任選一種便可 --> <!-- 對模型視圖名稱的解析,在請求時模型視圖名稱添加先後綴 --> <!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean>--> <!-- 針對freemarker的視圖配置 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="cache" value="true" /> <property name="prefix" value="" /> <property name="suffix" value=".ftl" /> <property name="contentType" value="text/html;charset=UTF-8"></property> <property name="requestContextAttribute" value="request" /> <property name="exposeSpringMacroHelpers" value="true" /> <property name="exposeRequestAttributes" value="true" /> <property name="exposeSessionAttributes" value="true" /> </bean> <!-- View resolvers can also be configured with ResourceBundles or XML files. If you need different view resolving based on Locale, you have to use the resource bundle resolver. --> <!-- 這個是針對返回視圖仍是json值的視圖配置 來分別處理同步和異步請求 --> <!--<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="mediaTypes"> <map> <entry key="html" value="text/html" /> <entry key="json" value="application/json" /> </map> </property> <property name="favorParameter" value="true" /> <property name="viewResolvers"> <list> <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="cache" value="true" /> <property name="prefix" value="" /> <property name="suffix" value=".ftl" /> <property name="contentType" value="text/html;charset=UTF-8"></property> <property name="requestContextAttribute" value="request" /> <property name="exposeSpringMacroHelpers" value="true" /> <property name="exposeRequestAttributes" value="true" /> <property name="exposeSessionAttributes" value="true" /> </bean> </list> </property> <property name="defaultContentType" value="text/html" /> </bean> --> </beans>
這時候咱們只須要在 每一個視圖配置裏面添加 <property name="order" value="orderValue"/> 這個屬性spring
這個配置表示解析器的優先級別。咱們將FreeMarkerViewResolver的級別設爲0,將InternalResourceViewResolver的級別設爲1。這樣,解析器就會優先使用 FreeMarkerViewResolver 進行解析,若是找不到相應的模板,就使用InternalResourceViewResolver進行解析,若是還找不到頁面,就會產生一個404錯誤!json
具體實例 稍後更新spring-mvc