图片上传下载+前端显示

上传下载

上传下载跟文件上传下载差不多,给文件后缀加个验证就行了,下面上传下载直通车
上传下载的链接

图片显示

前端代码

<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) {
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值