打开浏览器,查看错误信息:(Resource interpreted as Stylesheet but transferred with MIME type text/html)
TIM截图20181120104242.png
页面引入静态资源:html通过Thymeleaf模板引擎渲染的,css、js在静态资源的目录中;SpringBoot会自动映射静态资源的;有小伙伴不清楚的可以去看看:SpringBoot Web开发初体验
html代码:
TIM截图20181120104637.png
拦截器:自己实现拦截器实现WebMvcConfigurer接口中的,重写addInterceptors的方法
解决方案:放开对静态资源的拦截
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
//浏览器发送 /xt 请求来到success
registry.addViewController("/xt").setViewName("success");
registry.addViewController("/").setViewName("login");
registry.addViewController("/index.html").setViewName("login");
registry.addViewController("/main.html").setViewName("dashboard");
}
//注册拦截器
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 静态资源: *.css , *.js
registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
.excludePathPatterns("/index.html","/","/user/login","/asserts/**","/webjars/**");
}