当前位置:   article > 正文

Spring 拦截器_org.springframework.web.servlet.config.annotation

org.springframework.web.servlet.config.annotation
  1. import org.slf4j.Logger;
  2. import org.slf4j.LoggerFactory;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Component;
  5. import org.springframework.web.method.HandlerMethod;
  6. import org.springframework.web.servlet.HandlerInterceptor;
  7. import org.springframework.web.servlet.ModelAndView;
  8. @Component
  9. public class LoginInterceptor implements HandlerInterceptor {
  10. private static Logger log = LoggerFactory.getLogger(LoginInterceptor.class);
  11. @Override
  12. public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws NoLoginException, NoPermissionException {
  13. //此处做校验
  14. return true;
  15. }
  16. @Override
  17. public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
  18. }
  19. @Override
  20. public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
  21. }
  22. }
  1. import org.springframework.beans.factory.annotation.Autowired;
  2. import org.springframework.context.annotation.Configuration;
  3. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  4. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  5. /**
  6. * 拦截器配置
  7. */
  8. @Configuration
  9. public class LoginConfig implements WebMvcConfigurer {
  10. @Autowired
  11. private LoginInterceptor loginInterceptor;
  12. @Override
  13. public void addInterceptors(InterceptorRegistry registry) {
  14. registry.addInterceptor(loginInterceptor).addPathPatterns("/**");
  15. }
  16. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/576373
推荐阅读
相关标签
  

闽ICP备14008679号