我是靠谱客的博主 大胆猎豹,这篇文章主要介绍SpringBoot使用webjars处理静态资源,现在分享给大家,希望可以做个参考。

配置方法

  1. 打开WebJars - Web Libraries in Jars,找到jquery,
  2. 导入依赖
    复制代码
    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
15
public 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处理静态资源内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(93)

评论列表共有 0 条评论

立即
投稿
返回
顶部