当前位置: 首页> 健康> 知识 > 最新的新闻_企业咨询师_seo免费系统_搜索引擎营销的原理是什么

最新的新闻_企业咨询师_seo免费系统_搜索引擎营销的原理是什么

时间:2025/7/18 12:49:22来源:https://blog.csdn.net/weixin_45863786/article/details/142902556 浏览次数:0次
最新的新闻_企业咨询师_seo免费系统_搜索引擎营销的原理是什么

1.默认的静态资源目录

    /static
    /public 
    /resources
    /META-INF/resources

动态资源目录:/templates

2.resources静态资源目录图片存放

3. 静态资源访问
3.1.通过路径访问静态资源
    http://localhost:8080/a.jpg
    http://localhost:8080/b.jpg
    http://localhost:8080/c.png
    http://localhost:8080/d.jpg

3.2.通过配置类配置路径访问本地静态资源

1.config

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {//自定义路径mypic,  addResourceLocations指定访问资源所在目录registry.addResourceHandler("/mypic/**").addResourceLocations("file:C:\\Users\\Administrator\\Desktop\\images1\\");//自定义路径webjars访问,addResourceLocations映射该路径下的资源,resourceChain资源链
//        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/").resourceChain(true);}
}
2.访问结果展示

路径:http://localhost:8080/mypic/huangshanpic.webp

3.3.通过配置文件配置路径访问静态资源

(1).application.yml

web.pic-path=C:/Users/Administrator/Desktop/images1/
spring.mvc.static-path-pattern=/mypic/**
spring.web.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/public/,classpath:/static/,file:${web.pic-path}

web.pic-path:访问路径
spring.mvc.static-path-pattern:采用全部映射到mypic路径的方式
spring.web.resources.static-locations:配置允许访问的静态资源目录

(2).访问路径格式
    http://localhost:8080/mypic/a.jpg
    http://localhost:8080/mypic/b.jpg
    http://localhost:8080/mypic/c.png
    http://localhost:8080/mypic/d.jpg
    http://localhost:8080/mypic/web.pic-path配置本地路径下的图片名称

3.4. 通过引入打包静态资源的jar包形式访问

(1).静态资源打jar包

创建一个新的web工程,只存放静态资源

1).pom.xml

 <build><resources><resource><!--directory   将该路径下的资源(example/0.0.3/资源)打包targetPath  成该路径下存储--><directory>${project.basedir}/src/main/resources</directory><targetPath>${project.build.outputDirectory}/META-INF/resources/webjars</targetPath></resource></resources></build>

2).静态资源目录结构

3). package点击打包

 4).install到本地仓库

(2).主项目中引入依赖包

1).pom.xml

        <!--导入依赖的自定义静态资源webjars包--><dependency><groupId>com.openlab</groupId><artifactId>WWebjarsdemo</artifactId><version>1.0</version></dependency><!--为了不再管理版本号--><dependency><groupId>org.webjars</groupId><artifactId>webjars-locator-core</artifactId><version>0.35</version></dependency>

(3).路径访问
未引入webjars-locator-core的jar包:http://localhost:8080/webjars/example/版本号/huangshan.webp

引入webjars-locator-core的jar包:

http://localhost:8080/webjars/example/huangshan.webp

注意:如果主程序和引入打包的jar包静态资源下具备相同的目录结构,如:META-INF\resources\webjars\example\0.0.1\**,可能会出现路径访问失败的情况。

解决方法:clean主程序项目,重新运行。

(4).访问结果

关键字:最新的新闻_企业咨询师_seo免费系统_搜索引擎营销的原理是什么

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: