thymeleaf引入靜態js,css失效
- 配置properties文件
#thymeleaf訪問根路徑
spring.thymeleaf.prefix=classpath:/templates/
#後綴名
spring.thymeleaf.suffix=.html
#模板格式
spring.thymeleaf.mode=HTML5
#字符格式
spring.thymeleaf.encoding=UTF-8
#在呈现模板之前检查模板是否存在,默認true
spring.thymeleaf.check-template = true
#检查模版位置是否存在,默认为 true
spring.thymeleaf.check-template-location=true
#是否开启缓存,开发时可以设置为 false,默认为 true
spring.thymeleaf.cache=false
#Content-Type配置
spring.thymeleaf.servlet.content-type=text/html; charset=utf-8
#启用MVC Thymeleaf视图分辨率。
spring.thymeleaf.enabled=true
#spring.mvc.static-path-pattern=/static
- 可以重寫WebMvcConfigurationSupport ,配置攔截登錄及靜態文件加載路勁
@SpringBootConfiguration
public class LoginSupport extends WebMvcConfigurationSupport {
@Autowired
private LoginInterceptor loginInterceptor;
@Override
protected void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
.excludePathPatterns("/login","/verifyCode","/doLogin","/welcome");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/");
super.addResourceHandlers(registry);
}
}