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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

springmvc多个视图解析器管理跳转资源

發(fā)布時間:2024/10/6 c/c++ 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springmvc多个视图解析器管理跳转资源 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

springmvc多個視圖解析器管理跳轉(zhuǎn)資源

項目結(jié)構(gòu)

第一步:將所有資源交由springmvc管理

<servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring-servlet.xml</param-value></init-param> </servlet> <servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern> </servlet-mapping>

在springmvc配置文件中配置多個視圖解析器

根據(jù)屬性viewNames的value進行區(qū)分,*jsp*:處理器方法返回的資源包括jsp的則進來 <?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: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.xsdhttp://www.springframework.org/schema/mvchttps://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/context/spring-context.xsd"><!--基于上下文進行對組件的掃描--><context:component-scan base-package="com.yyjc.springmvc.handler"/><mvc:annotation-driven/><!--使用默認的Servlet來響應(yīng)靜態(tài)文件--><mvc:default-servlet-handler/><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/"/><property name="suffix" value=".jsp"/><property name="viewNames" value="*jsp*"/><property name="order" value="2"/></bean><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/"/><property name="suffix" value=".html"/><property name="viewNames" value="i*"/><property name="order" value="1"/><!--order:設(shè)置優(yōu)先級,order值越低,則優(yōu)先級越高--></bean> </beans>

第二步:處理器方法返回跳轉(zhuǎn)資源

注:方法返回結(jié)果可以是ModelAndView或者String

@RequestMapping("/userlogin.action")public String userLogin() {System.out.println("進來了");return "jsp/success";} /* @RequestMapping("/userlogin.action")public ModelAndView userLogin() {ModelAndView modelAndView = new ModelAndView();System.out.println("進來了");modelAndView.setViewName("index");return modelAndView;} */

總結(jié)

以上是生活随笔為你收集整理的springmvc多个视图解析器管理跳转资源的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。