一、背景
项目经常会上传文件,并且预览,如头像之类的,如果放置于项目中,更新项目会有问题。
二、方案
写入本地,不做介绍。
主要在于读取:
在tomcat的server.xml 文件中 Host标签中添加如下
1)windows中
<Context path="/appletcode" docBase="E:\home\crmmeeting\appletcode" debug="0" reloadable="true"></Context>
2)linux中
<Context path="/appletcode" docBase="/home/crmmeeting/appletcode" debug="0" reloadable="true"></Context>
前端访问
<img alt="重新生成" class="img-responsive" height="240" width="240" src="/appletcode/000298.jpg" onclick="reloadCode()">
意思就是path的路径能之道后面的全路径。
三、知识拓展
springboot对外文件
@Component
class WebConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//addResourceLocations指的是文件放置的目录,addResoureHandler指的是对外暴露的访问路径
String path=PathUtil.getPath()+"invoice/";
registry.addResourceHandler("/invoice/**").addResourceLocations("file:///"+path);
}
}