此处以JwtInterceptor 为例,不需要其它配置
@Componentpublic class JwtInterceptor extends HandlerInterceptorAdapter { @Autowired private Jwtutil jwtutil; @Autowired private SysUserService sysUserService; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String header = request.getHeader("Authorization"); if (!StringUtils.isEmpty(header)) { Claims claims = jwtutil.parsetToken(header); String username = (String) claims.get("username"); String role = (String) claims.get("role"); Integer sysUserId = Integer.valueOf(claims.getId()); SysUser sysUser = sysUserService.selectByPrimaryKey(sysUserId); if (sysUser==null) throw new UserNotLoginException(); request.setAttribute("sysUser", sysUser); request.setAttribute("sysUserId", sysUserId); request.setAttribute("username", username); request.setAttribute("role", role); } String url = request.getRequestURL().toString(); System.out.println(url); /** * * 此处所有请求放行 */ return true; }}