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

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

相关推荐
while(1){yan}14 小时前
Mybatis基础(详解)
spring boot·spring·java-ee·mybatis
sheji341614 小时前
【开题答辩全过程】以 基于springboot的健身房管理系统为例,包含答辩的问题和答案
java·spring boot·后端
张较瘦_17 小时前
Springboot3 | 核心注解实战教程
java·spring boot
Java水解20 小时前
Spring Boot:Java开发的神奇加速器(二)
spring boot·后端
Coder_Boy_20 小时前
基于SpringAI的企业级智能教学考试:基础资源构建模块
人工智能·spring boot
Coder_Boy_20 小时前
基于SpringAI的企业级智能教学考试平台模块二:核心执行模块内容
人工智能·spring boot
独自归家的兔21 小时前
基于 Doubao-Seedream-4.5 的单张图片生成后端接口实战
java·人工智能·spring boot·后端
刘一说21 小时前
Tomcat在Spring Boot集成原理及优化应用:深度解析与实战指南
java·spring boot·tomcat
禹中一只鱼21 小时前
【SpringBoot 配置文件】
java·spring boot·后端
JavaGuide1 天前
Spring Boot 3.3+Java 21+Spring AI+RustFS打造的智能面试平台开源啦!
spring boot·后端