SpringBoot设置虚拟路径映射绝对路径
2018-01-30 11:47
621 查看
上传图片到本地路径,得到的是一个绝对路径例如:D:\picpath\O48681516429132485.png
但是前台需要的数据是这样的 :http://localhost:8082/image/O48681516429132485.png
那么就要设置虚拟路径 /image/ = D:\picpath\ 了,下面我们就来代码实现下,作为一个负责任
的程序员,我把包也给你们复制过来了。
但是前台需要的数据是这样的 :http://localhost:8082/image/O48681516429132485.png
那么就要设置虚拟路径 /image/ = D:\picpath\ 了,下面我们就来代码实现下,作为一个负责任
的程序员,我把包也给你们复制过来了。
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) { //文件磁盘图片url 映射 //配置server虚拟路径,handler为前台访问的目录,locations为files相对应的本地路径 registry.addResourceHandler("/image/**").addResourceLocations("D:\\picpath\\"); } }是不是很简单呢?
相关文章推荐
- Spring Boot之配置虚拟映射路径
- spring boot 设置虚拟路径
- Spring Boot配置虚拟路径
- 【spring】关于location路径的设置(相对路径和绝对路径)
- spring boot内置tomcat设置虚拟目录
- springboot项目实现静态文件映射任意路径
- springboot 获取项目绝对路径
- springboot 获取项目绝对路径
- SpringBoot velocity 模板配置绝对路径的资源路径
- springboot 获取项目绝对路径
- 项目案例: Springboot中使用过滤器映射访问路径
- SpringBoot 配置图片虚拟路径
- 【spring】关于location路径的设置(相对路径和绝对路径)
- Server-U设置虚拟路径映射网络共享文件夹
- SpringBoot系列<四>视图解析、路径-资源映射、静态资源访问
- spring boot之spring mvc常用配置--路径匹配参数设置(7)
- Springboot配置静态资源url映射及对应的本地路径
- [Spring]设置property-placeholder绝对路径
- tomcat设置虚拟路径映射服务器指定的物理路径
- springBoot重新设置静态资源路径