springboot访问服务器本地静态文件的方法
2024-10-19 18:27:47
一、继承WebMvcConfigurerAdapter,重写addResourceHandlers,在registry里面配置访问路径和映射到的服务器本地路径。
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter{ @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("/file/static/*").addResourceLocations("file:E:\\springboot\\");
} }
结果如图:
在上述配置中,访问file/static/下的文件会被映射到本地项目E:\\springboot\\下的目录里面。
最新文章
- 在Linux主机上搭建SVN,用于同步提交修改,实现本地提交线上预览(SVN Hook功能实现)
- idhttp的用法
- cogs896 圈奶牛
- php-fpm的重启/关闭
- C语言文件函数
- android测试的相关概念以及单元测试
- EJB理解
- Bzoj 3171: [Tjoi2013]循环格 费用流
- C# 内存管理优化畅想(一)---- 大对象堆(LOH)的压缩
- 201512读书分享——读《做自己的No.1》“哪一天”是永远不会到来的
- TCP跟UDP乱侃
- nginx匹配规则说明以及匹配的优先级
- mysql中利用show profile很直观的看到查询缓存的作用。
- BUG——Celery ValueError: not enough values to unpack
- jQuery 文件上传插件:uploadify、swfupload
- linux -- Ubuntu报错“unable to locate package...”
- APP消息推送功能
- hdu6121 build a tree(树)
- TCO 2015 Round 2A DIV1
- iOS define 宏定义 和 const定义常量区别