zoukankan      html  css  js  c++  java
  • java登录拦截器

    /**
     * 登录拦截器
     * @author Administrator
     *
     */
    @Component
    public class LoginInterceptor implements HandlerInterceptor{//implements HandlerInterceptor
        
        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
              //当前登录账号
                HttpSession session = request.getSession();
                Admin admin = (Admin) session.getAttribute("admin");
                if (StringUtils.isEmpty(admin)){
                    response.sendRedirect("/login");
                    return false;
                }else {
                    return true;    
                }
    
        }
    
        @Override
        public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        }
    
        @Override
        public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        }
    }
    //静态资源拦截
    @Configuration
    public class WebAppConfig implements WebMvcConfigurer { @Autowired private LoginInterceptor loginInterceptor; @Autowired private Content content; @Override public void addInterceptors(InterceptorRegistry registry) { InterceptorRegistration interceptorRegistration = registry.addInterceptor(loginInterceptor); interceptorRegistration.excludePathPatterns("/error/**","/login","/check"); interceptorRegistration.excludePathPatterns("/static/**"); interceptorRegistration.addPathPatterns("/**"); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); //registry.addResourceHandler("/image/mpOa/headImg/**").addResourceLocations("file:"+content.getHeadImgPath()); } }
  • 相关阅读:
    WPF简单的分页控件实现
    WPF常用样式总结
    树:重建二叉树
    从尾到头打印链表
    字符串替换空格
    二维数组中的查找
    C#中转换运算符explicit、implicit、operator、volatile研究
    泛型实现常用算法
    .NET架构师知识普及
    .NET中扩展方法和Enumerable(System.Linq)
  • 原文地址:https://www.cnblogs.com/ch94/p/14741328.html
Copyright © 2011-2022 走看看