1. 程式人生 > >SpringMVC中的HandlerMapping

SpringMVC中的HandlerMapping

這是一個定義請求與處理器物件之間對映關係的介面。

這個類能夠被應用程式開發人員實現,但其實這個不是必要的,因為框架本身包含了BeanNameUrlHandlerMapping和SimpleUrlHandlerMapping,DefaultAnnotationHandlerMapping。前面那個是預設的,在application context中沒有註冊HandlerMapping bean的情況下。

HandlerMapping實現能夠支援對映攔截器,但也不是必須的。一個handler總是會被包裝在一個HandlerExcutionChain例項當中,並且和一些HandlerInterceptor例項同時存在。

DispatcherServlet會首先按照給定的順序呼叫每個HandlerInterceptor的preHandle方法,最後才會呼叫handler本身,前提是所有的preHandle方法都返回true。

其核心的方法是

HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception;

其返回值HandlerExecutionChain包含了一個handler物件以及一些攔截器。

如果沒有發現到匹配的,就返回null,但不會是一個錯誤。因為DispatcherServlet會查詢所有註冊好的HandlerMapping 來進行匹配。如果這都沒有發現一個匹配的hanler,則跑出一個錯誤。

相關推薦

SpringMVCHandlerMapping

這是一個定義請求與處理器物件之間對映關係的介面。 這個類能夠被應用程式開發人員實現,但其實這個不是必要的,因為框架本身包含了BeanNameUrlHandlerMapping和SimpleUrlHandlerMapping,DefaultAnnotationHandlerM

springmvcspringmvc如何上傳文件

doc 問題 ffffff color 遍歷 -c tip int imu 使用到的組件:可自行根據情況選擇版本 <!--上傳依賴包--> <dependency> <groupId

SpringMVCRequetContextListener說起

listener attribute 請求 bool 程序 div n) https 操作 零、引言 RequetContextListener從名字結尾Listener來看就知道屬於監聽器。 所謂監聽器就是監聽某種動作,在其開始(初始化)和結束(銷毀)的時候進行

springmvc配置servlet初始化類

調用 靜態類 its tomcat -m class cat 讀取 gmv <bean id="InitStart" lazy-init="false" init-method="InitSystem" class="my.spring.uitl.InitStart

SpringMVC的文件上傳

.get 界面 org 存在 編碼格式 docx 後綴 cti 時間 SpringMVC中的文件上

SpringMVCredirect跳轉後如何保存Model的數據?

bsp edi nbsp app delete del 支持 msg shtml @RequestMapping(value = "delete-user", method = RequestMethod.POST) public String deleteUser(Lon

Springmvc org.springframework.http.converter.json.MappingJackson2HttpMessageConverter依賴jackson包

otf dha 配置 beans framework 依賴包 ans cep tpm 1,問題詳情:Spring使用4.3.5.Release版本後 在SpringMvc配置文件中配置json 解析器後出現報錯信息 [org.springframework.w

SpringMVCIOC容器

pla 運行期 決定 text prot 容器 自動 -1 1.3 1.Spring作用: 1.生態體系龐大,全能型選手!【springmvc是其一個子模塊,jdbcTemplate能直接操作數據庫!】 2.將其他組件粘合在一起 3.IOC容器和AOP Spring的Io

springMVCRestful支持

restfu 同名 方法的參數 單變量 pda rust lin ont cor RESTFul支持 http://localhost:8090/user/doAdd.action?username=tony&age=8 http://localhost:8090/

SpringMVCcontroller返回json數據的兩種方法

rac new enter req imp 工具 response 返回 basepath SpringMVC中controller返回json數據的兩種方法 1.jsp的ajax請求: function getJson(){ $.ajax({ t

SpringMVC的一些註解

gmv pub pan else bsp break () 獲取參數 false @Controller:表明該類是一個Controller; @RequestMapping(參數) :為類或者方法定義一個url @RequestParam(value = "id" ):

SpringMVC獲取request對象的幾種方式

hello ext spring pub strong framework () frame -c 1.最簡單的方式(註解法) @Autowiredprivate HttpServletRequest request; 2.最麻煩的方法 a. 在web.xml中

SpringMVC的參數綁定總結

tps 快速入門 query required app http 客戶 接收 imp 眾所周知,springmvc是用來處理頁面的一些請求,然後將數據再通過視圖返回給用戶的,前面的幾篇博文中使用的都是靜態數據,為了能快速入門springmvc,在這一篇博文中,我將總結一下s

總結本次實訓springMVC常用的註解@,以後用到別的會持續更新

col ring key值 ppi div jsp頁面 ajax請求 map spa @Repository //dao層註解。聲明本層為dao層。 @serivce //service層。 @controller //con層。 @auto

SpringMVC的 JSR 303 數據校驗框架說明

bind 工作 電子 支持 length spring容器 error digits 獲取 JSR 303 是java為Bean數據合法性校驗提供的標準框架,它已經包含在JavaEE 6.0中。 JSR 303 通過在Bean屬性上標註類似於@NotNull、@Max等標

SOAspringmvcrestful服務的數據權限加密方式分享

enum 代碼 switch mes nis 應用名 sub 列表 ssa restful中數據權限加密方式有很多種,特別是針對於request json的方式加密,這裏詳細介紹了SOA中針對於get、post數據加密方式,保證數據傳輸中的安全性: Java代碼

SpringMVC使用Interceptor攔截器

lis elm auto let 發生 ins 系列 number ted 詳見:http://elim.iteye.com/blog/1750680 SpringMVC 中的Interceptor 攔截器也是相當重要和相當有用的,它的主要作用是攔截用戶的請求並進行相應的處

[轉]spring入門(六)【springMVC各數據源配置】

數據源 開源 文件 mysql 簡單 oot img log 自帶 在使用spring進行javaWeb開發的過程中,需要和數據庫進行數據交換,為此要經常獲取數據庫連接,使用JDBC的方式獲取數據庫連接,使用完畢之後再釋放連接,這種過程對系統資源的消耗無疑是很大的,這裏簡單

SpringMVC遇到頁面跳轉出現404錯誤的問題

書寫 one 錯誤 spa size 成功 問題: scan con 今天遇到了一個問題: 使用SpringMVC時,出現頁面無法跳轉的情況(404錯誤), 出現這個異常的原因在於SpringMVC的配置文件中控制器的配置書寫錯誤: 原代碼: <context:co

springMVC的註解@RequestParam與@PathVariable的區別

actor nal lencod mat 控制 關系 tor oid 沒有 @PathVariable綁定URI模板變量值 @PathVariable是用來獲得請求url中的動態參數的 @PathVariable用於將請求URL中的模板變量映射到功能處理方法的參數上。//配