需要在application.properties文件里配置如下配置项:
#配置本地资源路径,必须以/结尾
filePath=E:/file/
#配置静态资源拦截方式和静态资源路径
spring.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${filePath}
比如,E:/file/ 路径下有一个 test.jpg的图片,访问该图片的地址即为:http://ip:port/test.jpg
本文详细介绍了如何在Spring MVC中配置静态资源,包括设置本地资源路径和定义静态资源的拦截方式。通过配置application.properties文件,可以轻松实现对图片等静态资源的访问。
355

被折叠的 条评论
为什么被折叠?



