上传下载
上传下载跟文件上传下载差不多,给文件后缀加个验证就行了,下面上传下载直通车
上传下载的链接
图片显示
前端代码
<table class="layui-table" id="fileDiv" lay-filter="fileDiv">
<tr>
<th>图片</th>
<th>图片名</th>
<th>上传时间</th>
<th>操作</th>
</tr>
<tr th:each="file:${files}">
<th><img th:src="@{'/files/'+${file.newFilename}}"/></th>
<th><lable th:text="${file.fileName}"></lable></th>
<th><label th:text="${file.createTime}"></label></th>
<th><a th:href="@{'/files/'+${file.newFilename}}" download="">下载</a></th>
</tr>
</table>
后端代码
将/files/** 开头的资源路径转换成你上传的路径,结合文件上传看,下载也可以,不过文件名就没办法改了
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String dir = FileConfig.FILE_ADDRESS.replace("\\","/");
registry.addResourceHandler("/files/**").addResourceLocations("file:///"+dir);
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
}
}