HandlerInterceptor - 自定義攔截器

kiss_sheep發表於2024-03-21

自定義一個類實現HandlerInterceptor介面,加上@Component註解。
根據需要重寫方法

public interface HandlerInterceptor {
    default boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        return true;
    }

    default void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
    }

    default void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
    }
}

相關文章