Springboot实现文件上传下载的简单demo

本文通过步骤演示如何在Springboot中实现文件上传和下载功能。首先新建Springboot项目,配置阿里云镜像加速,然后编写文件上传接口并用Postman测试,接着实现文件下载接口,最后展示前端如何通过fetch上传文件并获取下载链接。
摘要由CSDN通过智能技术生成

新建一个Springboot项目

File -> New Project 根据下图指引做:
在这里插入图片描述

点击next,选择Springboot版本和组件,版本可以跟我不同:

在这里插入图片描述

点击 Finish完成项目创建,然后开始导入Pom依赖

在这里插入图片描述

如果依赖下载的太慢的话,可以使用aliyun,方法是在你的 pom.xml里加入下面的代码:

<repositories>
        <repository>
            <id>nexus-aliyun</id>
            <name>nexus-aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>public</id>
            <name>aliyun nexus</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

在这里插入图片描述
加完之后再刷新一下:
在这里插入图片描述

导入依赖之后会出现Springboot的启动按钮

在这里插入图片描述

直接点击绿色的三角启动运行项目。运行效果:
在这里插入图片描述

看到这个 8080 表示你的项目启动好了

开始写文件上传接口

package com.example.demo;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping</
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值