文件上传之使用一个属性接收多个文件

在开发过程中,可能遇到这样的业务:文件上传时个数不定,这样我们不能枚举出所有的文件name,这种情况下我们可以使用一个name将所有的文件接收下来;

html代码
复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="http://localhost:8021/xxx/upload1" method="post" enctype="multipart/form-data">

    <input type="file" name="file"><br/>
    <input type="file" name="file"><br/>
    <input type="file" name="file"><br/>
    <input type="file" name="file"><br/>
    <input type="file" name="file"><br/><br/>
    <button type="submit">提交</button>
</form>

</body>
</html>
controller代码

使用springboot或者spring mvc框架

复制代码
    @PostMapping("/upload1")
    public String up(@RequestPart(value = "file") List<MultipartFile> fileList) {
        fileList.forEach(a -> {
            System.out.println(a.getOriginalFilename() + "-->" + a.getSize());
        });
        return "success";
    }

这样就接收到了所有文件

over~~

相关推荐
小荷才露尖尖角,早有蜻蜓立上头6 小时前
SpringBoot+QQ邮箱发送邮件
spring boot
头发还在的女程序员8 小时前
Java在线租房系统源码解析:Spring Boot+Vue 3+UniApp房源管理与预约看房方案
java·vue.js·spring boot·租房小程序·租房系统·租房软件
FYKJ_20108 小时前
springboot同人周边订单管理系统48955-计算机毕业设计、课程设计
java·javascript·vue.js·spring boot·django·php·课程设计
yuyuxun11 天前
协同过滤的校园二手物品智能推荐系统的设计与实现 毕业设计-附源码40082
javascript·vue.js·spring boot·python·数据分析·django·课程设计
LGL6030A1 天前
Java学习历程31——初识Spring Boot
java·spring boot·学习
阿达和自己1 天前
springboot学习-springboot引入MyBatis-Plus
spring boot·学习·mybatis
Jackzhang2 天前
[运维排障实录] 第一次遇到 502 别急着重启:按「一条线」把问题查清楚
spring boot
学长毕设2 天前
基于SpringBoot的景点管理系统-附源码
java·spring boot·后端
知守观2 天前
一个方法两个触发口:反编译 XXL-Job 后,我看清了 inner/job 子包的裸奔现状
java·spring boot·微服务
瑞雪兆丰年兮2 天前
JavaWeb-day14-SpringBootWeb原理篇
java·开发语言·spring boot·spring·bean·mybatis·javaweb