本文介绍了SpringBoot使用自定义注解实现权限拦截的示例,分享给大家,具体如下:
HandlerInterceptor(处理器拦截器)
常见使用场景
使用自定义注解实现权限拦截
首先HandlerInterceptor了解
在HandlerInterceptor中有三个方法:
public interface HandlerInterceptor { // 在执行目标方法之前执行 boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler)throws Exception; // 执行目标方法之后执行 void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)throws Exception; // 在请求已经返回之后执行 void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)throws Exception; }