拦截器中获取注解 来源:https://blog.csdn.net/wangmx1993328/article/details/81030268/
public class JWTInterceptor implements HandlerInterceptor { private SysSettingService sysSettingService; //构造函数传入Service public JWTInterceptor(SysSettingService _sysSettingService) { sysSettingService = _sysSettingService; } @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (handler instanceof HandlerMethod) { //方法处理器, 请求的目标方法。RequirePermissions是自定义注解。 HandlerMethod handlerMethod = (HandlerMethod) handler; //1: 获取目标方法上的指定注解,不存在时,返回 Null RequirePermissions methodPermissions = handlerMethod.getMethodAnnotation(RequirePermissions.class); //2: 获取目标方法所在类上的指定主键,不存在时,返回 Null RequirePermissions classPermissions = handlerMethod.getMethod().getDeclaringClass().getAnnotation(RequirePermissions.class); if (methodPermissions != null) { //获取注解中的数据 String[] permissions = methodPermissions.values(); } }
} }
标签:拦截器,SpringBoot,Service,sysSettingService,获取,注解,RequirePermissions From: https://www.cnblogs.com/xsj1989/p/18283864