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

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

相关推荐
whyfail3 小时前
前端学 Spring Boot(2):一次点击,如何穿过整个后端?
前端·spring boot·后端
乔伊酱3 小时前
我被列表查询折磨了 7 年,直到有一天我发现它不是 ORM 的事!
spring boot·graphql
霸道流氓气质5 小时前
SpringBoot中基于 AES-GCM + KMS 密钥管理的数据加解密 Starter 实践
java·数据库·spring boot
乐观的Terry6 小时前
8、发布系统-完整流水线的核心
java·spring boot·spring·spring cloud
万亿少女的梦1686 小时前
基于Spring Boot的游戏交易管理系统设计与实现
java·spring boot·mysql·系统设计·交易管理
Q渡劫7 小时前
Redis 从安装到集成 Spring Boot 完整总结
spring boot
ruleslol9 小时前
SpringBoot26-@Configuration + @Component
spring boot
霸道流氓气质10 小时前
SpringBoot中使用JasperReports 报表引擎 — 介绍、原理与使用实践
java·spring boot·后端
风景的人生11 小时前
流式输出与springboot中的响应式编程
java·spring boot·ai编程
dkbnull11 小时前
Spring Boot依赖注入方式对比详解
spring boot·spring