本文研究的主要是SpringMVC中的攔截器的介紹及實(shí)例代碼,配置等內(nèi)容,具體如下。

Springmvc的處理器攔截器類(lèi)似于Servlet 開(kāi)發(fā)中的過(guò)濾器Filter,用于對(duì)處理器進(jìn)行預(yù)處理和后處理。本文主要總結(jié)一下springmvc中攔截器是如何定義的,以及測(cè)試攔截器的執(zhí)行情況和使用方法。
1. springmvc攔截器的定義和配置 1.1 springmvc攔截器的定義在springmvc中,定義攔截器要實(shí)現(xiàn)HandlerInterceptor接口,并實(shí)現(xiàn)該接口中提供的三個(gè)方法,如下:
//測(cè)試攔截器1
public class HandlerInterceptor1 implements HandlerInterceptor{
@Override
public Boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
System.out.println("HandlerInterceptor1....preHandle");
//false表示攔截,不向下執(zhí)行;true表示放行
return true;
}
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
System.out.println("HandlerInterceptor1....postHandle");
}
@Override
public void afterCompletion(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex)
throws Exception {
System.out.println("HandlerInterceptor1....afterCompletion");
}
}
網(wǎng)頁(yè)標(biāo)題:SpringMVC中的攔截器詳解及代碼示例-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)路徑:http://chinadenli.net/article48/cejhep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、虛擬主機(jī)、網(wǎng)站排名、域名注冊(cè)、商城網(wǎng)站、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容