本文介紹了SpringBoot使用自定義注解實(shí)現(xiàn)權(quán)限攔截的示例,分享給大家,具體如下:
HandlerInterceptor(處理器攔截器)
常見(jiàn)使用場(chǎng)景
使用自定義注解實(shí)現(xiàn)權(quán)限攔截
首先HandlerInterceptor了解
在HandlerInterceptor中有三個(gè)方法:
public interface HandlerInterceptor { // 在執(zhí)行目標(biāo)方法之前執(zhí)行 boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler)throws Exception; // 執(zhí)行目標(biāo)方法之后執(zhí)行 void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)throws Exception; // 在請(qǐng)求已經(jīng)返回之后執(zhí)行 void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)throws Exception; }