在将公司的SpringMVC小项目改成SpringBoot的时候,记录一下springboot访问html的方式
1. 在resource
下面创建templates
或者static
文件夹,新建html
2.配置文件表明静态页面的位置
spring:
resources:
static-locations: classpath:templates/, classpath:static/ ,classpath:public/
3. 拦截器放过
代码块1
@Override
public void addInterceptors(InterceptorRegistry registry) {
logger.info(BaseVar.STRART_WITH +"进入token拦截配置类");
// 注册拦截器,我们自己写好的拦截器需要通过这里添加注册才能生效
InterceptorRegistration registration = registry.addInterceptor(tokenInterceptor);
registration.addPathPatterns("/**");
registration.excludePathPatterns(
"/static/**",
"/templates/**",
"/**/*.html",
"/**/*.js",
"/**/*.css",
"/**/*.json",
"/**/*.icon"
);
logger.info(BaseVar.STRART_WITH +"配置拦截或放行成功");
//Authorization拦截器
}
代码块2
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
System.out.println(BaseVar.STRART_WITH + "开始设置静态资源");
// 解决静态资源无法访问 如果你的静态文件在这两个文件夹下面都有 此处两个都需要
registry.addResourceHandler("/templates/**")
.addResourceLocations("classpath:/templates/");
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");*/
}