日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring MVC配置多个视图解析器(FreeMarker,JSP)

發布時間:2024/9/30 javascript 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring MVC配置多个视图解析器(FreeMarker,JSP) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Spring MVC配置多個視圖解析器(FreeMarker,JSP)

Spring MVC開發過程中,有時候需要多個視圖解析器策略來解析視圖名稱,出現這個情況怎么解決?

通過“order”屬性來聲明優先級,order值越低,則優先級越高。例如:

?

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><!-- 自動掃描com.baobaotao.web 包下的@Controller標注的類控制器類 --><context:component-scan base-package="com.feng.web" /><!-- 啟動Spring MVC的注解功能,完成請求和注解POJO的映射 --><mvc:annotation-driven/><!-- 對模型視圖名稱的解析,在請求時模型視圖名稱添加前后綴 --><!-- FreeMarker基礎設施及視圖解析器配置 --><beanclass="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"p:templateLoaderPath="/WEB-INF/ftl" p:defaultEncoding="UTF-8"><property name="freemarkerSettings"><props><prop key="classic_compatible">true</prop></props></property></bean><beanclass="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"p:order="0" p:suffix=".ftl" p:contentType="text/html; charset=utf-8" /> <beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"p:order="1" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /><bean id="multipartResolver"class="org.springframework.web.multipart.commons.CommonsMultipartResolver"p:defaultEncoding="utf-8" /><bean id="messageSource"class="org.springframework.context.support.ResourceBundleMessageSource"p:basename="i18n/messages" /><!--WEB異常解析處理--><bean id="exceptionResolver" class="com.baobaotao.web.ForumHandlerExceptionResolver"><property name="defaultErrorView"><value>fail</value></property><property name="exceptionMappings"><props><prop key="java.lang.RuntimeException">fail</prop></props></property></bean> </beans>


注意:

1:InternalResourceViewResolver必須賦予給最低的優先級(最大的order值),因為不管返回什么視圖名稱,它都將解析視圖。如果它的優先級高于其它解析器的優先級的話,它將使得其它具有較低優先級的解析器沒有機會解析視圖。

2:如果Controller中返回視圖加了后綴jsp或者ftl,在配置中就不要加入suffix配置,否則會找不到頁面。

總結

以上是生活随笔為你收集整理的Spring MVC配置多个视图解析器(FreeMarker,JSP)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。