如何使用SpringBoot配置一個(gè)攔截器?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
在SpringBoot中配置攔截器,主要有下面兩個(gè)步驟:
1、繼承接口 HandlerInterceptor,根據(jù)需要重寫(xiě)其中的三個(gè)類。
2、在配置類中注入該類。
public class MyInterceptor implements HandlerInterceptor { //controller執(zhí)行之前 @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { System.out.println("preHandler......"); return true; } //執(zhí)行完controller執(zhí)行之后、視圖渲染前調(diào)用,可以在該方法里獲取或者修改model @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { System.out.println("postHandler......"); } //一般用于清理資源 @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { System.out.println("afterCompletion......"); } }
新聞名稱:如何使用SpringBoot配置一個(gè)攔截器-創(chuàng)新互聯(lián)
轉(zhuǎn)載來(lái)于:http://www.rwnh.cn/article46/hojeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、Google、App設(shè)計(jì)、網(wǎng)站設(shè)計(jì)、商城網(wǎng)站、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)