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

在开发过程中,可能遇到这样的业务:文件上传时个数不定,这样我们不能枚举出所有的文件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~~

相关推荐
陈果然DeepVersion18 小时前
Java大厂面试真题:Spring Boot微服务+Kafka消息队列+AIGC场景实战问答全解析
spring boot·redis·微服务·kafka·消息队列·aigc·java面试
程序猿ZhangSir19 小时前
Spring Boot 项目实现邮件推送功能 (以QQ邮箱为例)
java·数据库·spring boot
JosieBook19 小时前
【SpringBoot】30 核心功能 - 单元测试 - JUnit5 单元测试简介与常用注解实战详解
spring boot·后端·单元测试
韩立学长19 小时前
【开题答辩实录分享】以《植物病虫害在线答疑小程序的设计与实现》为例进行答辩实录分享
spring boot·小程序·vue
玛卡巴卡0120 小时前
Maven 从入门到实战:搞定依赖管理与 Spring Boot 项目构建
java·spring boot·maven
جيون داد ناالام ميづ20 小时前
Spring Boot 核心原理(一):基础认知篇
java·spring boot·后端
夏之小星星21 小时前
Springboot结合Vue实现分页功能
vue.js·spring boot·后端
韩立学长21 小时前
【开题答辩实录分享】以《自动售货机刷脸支付系统的设计与实现》为例进行答辩实录分享
vue.js·spring boot·后端
ljh_learn_from_base1 天前
【spring boot 使用apache poi 生成和处理word 文档】
java·spring boot·word·apache
bug攻城狮1 天前
SpringBoot响应封装:Graceful Response vs 自定义通用响应类选型指南
java·spring boot·后端·http