springboot themaleaf 第一次进页面不加载css

近期在做springboot +themaleaf项目中遇到首页css样式不加载情况,后来发现是注册拦截器时没有加入css样式,下边是最开始代码

 

 public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor( new LoginHandleInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/index.html",  // 排除掉首页请求
                        "/",              // 排除掉首页请求
                     ) ;

        //registry.addInterceptor(new HandlerInterceptor()).

    }

第一次访问登录页面的时候,对应的js css呗拦截器拦截,就没有加载,只需要把对应的css,jquery等放入到拦截器中就可以了

 public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor( new LoginHandleInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/index.html",  // 排除掉首页请求
                        "/",              // 排除掉首页请求
                        "/user/login",  
                        "/asserts/css/*.css",
                        "/asserts/img/*.svg",
                        "/asserts/js/*.js",
                        "/webjars/bootstrap/4.1.1/css/*.css",
                         "/mancenter/*",
                        "/error", "/asserts/lib/jquery/*","/asserts/lib/*.js") ;

        //registry.addInterceptor(new HandlerInterceptor()).

    }

 

你可能感兴趣的:(#,Springboot,themaleaf)