我想使用本地引导文件css和js,因为我的tomcat服务器上没有互联网。但这是行不通的。
请帮助我!
MVC配置:
@Configuration
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {
@Value("${upload.path}")
private String uploadPath;
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/orders/**")
.addResourceLocations("file:/" + uploadPath + "/");
registry.addResourceHandler("/img/**")
.addResourceLocations("classpath:/img/");
registry.addResourceHandler("/js/**")
.addResourceLocations("classpath:/js/");
}
}
在html页面中:
<link href="/js/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="/js/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="/js/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>