配置方法
- 打开WebJars - Web Libraries in Jars,找到jquery,
- 导入依赖 复制代码1
2
3
4
5<dependency> <groupId>org.webjars</groupId> <artifactId>jquery</artifactId> <version>3.6.0</version> </dependency>
3. 在resources文件夹下,建立static,public,resources文件夹,其中3个文件夹的文件访问优先级为,resources>public>static。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15public void addResourceHandlers(ResourceHandlerRegistry registry) { if (!this.resourceProperties.isAddMappings()) { logger.debug("Default resource handling disabled"); } else { this.addResourceHandler(registry, "/webjars/**", "classpath:/META-INF/resources/webjars/"); this.addResourceHandler(registry, this.mvcProperties.getStaticPathPattern(), (registration) -> { registration.addResourceLocations(this.resourceProperties.getStaticLocations()); if (this.servletContext != null) { ServletContextResource resource = new ServletContextResource(this.servletContext, "/"); registration.addResourceLocations(new Resource[]{resource}); } }); } }
根据代码,如果在properties文件中建立了映射,则不会自动访问resources的文件夹。
最后
以上就是大胆猎豹最近收集整理的关于SpringBoot使用webjars处理静态资源的全部内容,更多相关SpringBoot使用webjars处理静态资源内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复