spring mvc学习(45):springMVC的三大组件
生活随笔
收集整理的這篇文章主要介紹了
spring mvc学习(45):springMVC的三大组件
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
SpringMvc框架結(jié)構(gòu)圖
- 處理器映射器:用戶請(qǐng)求路徑到Controller方法的映射
- 處理器適配器:根據(jù)handler(controlelr類)的開(kāi)發(fā)方式(注解開(kāi)發(fā)/其他開(kāi)發(fā)) 方式的不同區(qū)尋找不同的處理器適配器
-
視圖解析器:根據(jù)handler返回的view地址文件類型(jsp/pdf….)去尋找相應(yīng)的視圖解析器來(lái)進(jìn)行解析
SpringMvc框架配置要點(diǎn)1:應(yīng)該在SpirngMvc的核心配置文件中配置處理器映射器和處理器適配器,否則SpringMvc就會(huì)去/org/springframework/web/servlet/DispatcherServlet.properties這個(gè)文件中去依次去找處理器映射器和處理器適配器,這樣每一次的請(qǐng)求都會(huì)去依次判斷,這樣的效率會(huì)很慢的。
但是上面的配置最新版的注解處理器映射器和處理器適配器仍然不好,如果官方后續(xù)版本升級(jí)后續(xù)仍然會(huì)升級(jí)方法,這個(gè)類仍然或有可能過(guò)時(shí),此時(shí)在項(xiàng)目中再修改就有些麻煩,此時(shí)我們可以只需要配置一個(gè)注解驅(qū)動(dòng)就行了
<!-- 注解驅(qū)動(dòng):作用:替我們自動(dòng)配置最新版的注解的處理器映射器和處理器適配器--><mvc:annotation-driven></mvc:annotation-driven>SpringMvc配置視圖解析器可配可不配
<!-- 配置視圖解析器 作用:在controller中指定頁(yè)面路徑的時(shí)候就不用寫(xiě)頁(yè)面的完整路徑名稱了,可以直接寫(xiě)頁(yè)面去掉擴(kuò)展名的名稱--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 真正的頁(yè)面路徑 = 前綴 + 去掉后綴名的頁(yè)面名稱 + 后綴 --><!-- 前綴 --><property name="prefix" value="/WEB-INF/jsp/"></property><!-- 后綴 --><property name="suffix" value=".jsp"></property></bean>下面給出完整的SpringMvc的核心配置文件
<?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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><!-- 配置@Controller注解掃描 --><context:component-scan base-package="cn.itheima.controller"></context:component-scan><!-- 注解驅(qū)動(dòng):作用:替我們自動(dòng)配置最新版的注解的處理器映射器和處理器適配器--><mvc:annotation-driven></mvc:annotation-driven><!-- 配置視圖解析器 作用:在controller中指定頁(yè)面路徑的時(shí)候就不用寫(xiě)頁(yè)面的完整路徑名稱了,可以直接寫(xiě)頁(yè)面去掉擴(kuò)展名的名稱--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 真正的頁(yè)面路徑 = 前綴 + 去掉后綴名的頁(yè)面名稱 + 后綴 --><!-- 前綴 --><property name="prefix" value="/WEB-INF/jsp/"></property><!-- 后綴 --><property name="suffix" value=".jsp"></property></bean></beans>雜家不如專家,精益求精
總結(jié)
以上是生活随笔為你收集整理的spring mvc学习(45):springMVC的三大组件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 背包问题 c语言版
- 下一篇: 游戏用户体验指标_电子游戏如何超越游戏化