1 新增配置类
package com.ps.learn.socketio.config;
import org.spring work.beans.factory.annotation.Value;
import org.spring work.context.annotation.Configuration;
import org.spring work.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.spring work.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Author:ZhuShangJin
* Date:2018/12/19
*/
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
@Value(\"${out.resource.path}\")
private String path;
/**
* 访问外部文件配置,访问D盘下文件
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//配置server虚拟路径,handler为jsp中访问的目录,locations为image相对应的本地路径
registry.addResourceHandler(\"/image/**\").addResourceLocations(path);
}
}
2、application.properties配置文件添加外部文件地址
out.resource.path=file:D://upload/
3 访问
我们将1.png文件上传到D盘的upload文件夹后,那么在页面端访问则通过:http://127.0.0.1/image/1.png
继续阅读与本文标签相同的文章
-
走,我们一起让改变发生
2026-05-18栏目: 教程
-
互联网娱乐的风口浪尖下,老虎游戏机该如何选择?
2026-05-18栏目: 教程
-
道屹道:即时聊天APP开发 符合当前的时代潮流
2026-05-18栏目: 教程
-
微软前CEO鲍尔默,会成为下一个库克吗?商业模式错误
2026-05-18栏目: 教程
-
加速4G、5G网络演进 全“芯”展锐出新招
2026-05-18栏目: 教程
