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

歡迎訪問 生活随笔!

生活随笔

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

c/c++

springmvc十六:视图解析

發布時間:2025/6/15 c/c++ 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springmvc十六:视图解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?spring.xml配置視圖解析器如下:

<?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:mvc="http://www.springframework.org/schema/mvc"xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><context:component-scan base-package="com.atchina"></context:component-scan><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/pages/"></property><property name="suffix" value=".jsp"></property></bean> </beans>

方法執行后的返回值會作為頁面地址參考,轉發或者重定向到頁面。

視圖解析器可能會進行頁面地址的拼串。

?

forward前綴指定一個轉發操作

/*** forward:轉發到一個頁面* /hello.jsp 轉發當前項目下的hello.jsp* * forward:/hello.jsp, 視圖解析器不會在這個返回值加前后綴* forward:/hello.jsp 一定要加上/,如果不加/就是相對路徑,容易出問題*/@RequestMapping("/hello3")public String hello3(){return "forward:/hello.jsp";}/*** forward:轉發到一個請求*/@RequestMapping("/hello4")public String hello4(){return "forward:/hello3";}

重定向redirect

/*** 重定向到hello.jsp頁面 , 視圖解析器不會在這個返回值加前后綴* 轉發: forward: 轉發的路徑* 重定向: redirect:重定向的路徑* /hello.jsp 代表就是從當前項目下開始,SpringMvc會為路徑自動的拼接上項目名 */@RequestMapping("/hello5")public String hello5(){return "redirect:/hello.jsp";}/*** 重定向一個請求*/@RequestMapping("/hello6")public String hello6(){return "redirect:/hello5";}

?

視圖解析流程

? 1. 任何方法的返回值,最終都會被包裝成ModelAndView對象。

2. 該方法處理視圖渲染流程,將域中的數據在頁面展示:頁面就是用來渲染模型數據的。

? ? processDispatchResult(processedRequest, response, mappedHandler, mv, dispatchException); ?// 來到頁面的方法

3. 調用render(mv, request, response);渲染頁面

4. View 和 ViewResolver?

? ViewResolver的作用是根據視圖名(方法的返回值)得到View對象。

public interface ViewResolver {/*** Resolve the given view by name.* <p>Note: To allow for ViewResolver chaining, a ViewResolver should* return {@code null} if a view with the given name is not defined in it.* However, this is not required: Some ViewResolvers will always attempt* to build View objects with the given name, unable to return {@code null}* (rather throwing an exception when View creation failed).* @param viewName name of the view to resolve* @param locale Locale in which to resolve the view.* ViewResolvers that support internationalization should respect this.* @return the View object, or {@code null} if not found* (optional, to allow for ViewResolver chaining)* @throws Exception if the view cannot be resolved* (typically in case of problems creating an actual View object)*/View resolveViewName(String viewName, Locale locale) throws Exception;}

5. 怎么根據方法的返回值(視圖名)得到View對象?

? ?所有配置的視圖解析器都會嘗試根據視圖名(方法的返回值)得到View(視圖)對象;如果能得到View對象就返回,得不到就換下一個視圖解析器。

protected View resolveViewName(String viewName, Map<String, Object> model, Locale locale,HttpServletRequest request) throws Exception {for (ViewResolver viewResolver : this.viewResolvers) {// ViewResolver視圖解析器根據方法的返回值,得到一個View對象View view = viewResolver.resolveViewName(viewName, locale);if (view != null) {return view;}}return null;}

??

調用View對象的render方法

@Overridepublic void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {if (logger.isTraceEnabled()) {logger.trace("Rendering view with name '" + this.beanName + "' with model " + model +" and static attributes " + this.staticAttributes);}Map<String, Object> mergedModel = createMergedOutputModel(model, request, response);prepareResponse(request, response);// 渲染要給頁面輸出的所有數據renderMergedOutputModel(mergedModel, getRequestToExpose(request), response);}

?InternalResourceView類

@Overrideprotected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {// Expose the model object as request attributes.// 將模型中的數據放在請求域中exposeModelAsRequestAttributes(model, request);// Expose helpers as request attributes, if any.exposeHelpers(request);// Determine the path for the request dispatcher.String dispatcherPath = prepareForRendering(request, response);// Obtain a RequestDispatcher for the target resource (typically a JSP).RequestDispatcher rd = getRequestDispatcher(request, dispatcherPath);if (rd == null) {throw new ServletException("Could not get RequestDispatcher for [" + getUrl() +"]: Check that the corresponding file exists within your web application archive!");}// If already included or response already committed, perform include, else forward.if (useInclude(request, response)) {response.setContentType(getContentType());if (logger.isDebugEnabled()) {logger.debug("Including resource [" + getUrl() + "] in InternalResourceView '" + getBeanName() + "'");}rd.include(request, response);}else {// Note: The forwarded resource is supposed to determine the content type itself.if (logger.isDebugEnabled()) {logger.debug("Forwarding to resource [" + getUrl() + "] in InternalResourceView '" + getBeanName() + "'");}rd.forward(request, response);}}

? 總結: 視圖解析器只是為了得到視圖對象;視圖對象才能真正的轉發(將模型數據全部放在請求域中)或者重定向到頁面;視圖對象才能真正的渲染視圖。

?

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的springmvc十六:视图解析的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 一区二区三区四区欧美 | 欧美日韩丝袜 | 国产精品欧美精品 | 国产精品高潮呻吟视频 | 91色片 | 4444亚洲人成无码网在线观看 | 天堂综合网久久 | 波多野结衣黄色片 | 亚洲综合精品在线 | 国产片在线播放 | 国产乱码一区二区三区 | 中文字幕123 | 国产亚洲黄色片 | 黑人vs日本人ⅹxxxhd | 51国产偷自视频区视频 | 一区二区视屏 | 欧美综合国产 | 人妻精品一区二区三区 | 亚洲成人av中文字幕 | 日韩电影在线观看中文字幕 | 三级视频网站在线观看 | 国产电影免费观看高清完整版视频 | 中文字幕不卡在线观看 | 精品精品精品 | 国产精品久久久久久久久久久久久久久久久久 | 中文字幕黄色av | 一区二区三区精品视频 | 97se.com| 少妇高潮淫片免费观看 | 亚洲色鬼 | 美丽姑娘免费观看在线观看 | 国产三级视频在线播放 | 国产男女裸体做爰爽爽 | 国产欧美在线观看不卡 | 爱爱小视频免费看 | 久久538 | 韩漫动漫免费大全在线观看 | 国产一区二区色 | 成人丁香婷婷 | 精品国产一级 | 香蕉狠狠爱视频 | 好吊色欧美一区二区三区视频 | 91看片淫黄大片 | 午夜剧场免费观看 | 成人黄色动漫在线观看 | 91在线看视频 | 91高清在线免费观看 | av私库在线观看 | 99久久精品免费看国产 | 国产视频一二三四区 | 青青国产精品视频 | 日韩激情小视频 | 成人福利av | 色哒哒影院 | 丰满少妇影院 | 乱精品一区字幕二区 | 超碰在线人人 | 狠狠亚洲 | 日批视频在线免费看 | 向日葵视频在线播放 | 欧美日韩在线观看免费 | 欧美视频一区二区 | 悠悠色在线 | 先锋资源av网 | 色综合久久中文字幕无码 | 国产精品丝袜一区 | 久久黄色影院 | 91中文字幕 | 久久露脸国语精品国产91 | 国产又粗又猛视频 | av国产精品 | 日本免费不卡一区二区 | 人人cao| 日韩欧美xxxx | 黄色不卡av| 国产精品www| 久热这里只有精品在线 | 久久久久久黄色 | 91精产国品一二三区在线观看 | 日本色网址 | 成人免费黄色小视频 | 日韩性欧美 | 国产无遮挡免费观看视频网站 | 19禁大尺度做爰无遮挡电影 | 牛夜精品久久久久久久99黑人 | 男女互操 | 欧美视频一区二区三区四区 | 久久久久久久久久久电影 | 91成人在线免费观看 | 黄色免费看视频 | 伊人夜夜 | 日韩视频三区 | 亚洲a∨无码无在线观看 | 国产亚洲精品精品国产亚洲综合 | www.夜夜爱 | 国产免费一区二区三区在线播放 | 国产乱真实合集 | 亚洲色偷精品一区二区三区 | 日本不卡在线视频 |