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

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

相关推荐
riNt PTIP9 小时前
SpringBoot创建动态定时任务的几种方式
java·spring boot·spring
星晨羽10 小时前
西门子机床opc ua协议实现变量读写及NC文件上传下载
java·spring boot
yuweiade11 小时前
Spring Boot 整合 Redis 步骤详解
spring boot·redis·bootstrap
三水不滴12 小时前
SpringAI + SpringDoc + Knife4j 构建企业级智能问卷系统
经验分享·spring boot·笔记·后端·spring
2601_9498146912 小时前
Docker部署Spring Boot + Vue项目
vue.js·spring boot·docker
RDCJM15 小时前
Springboot的jak安装与配置教程
java·spring boot·后端
志飞16 小时前
springboot配置可持久化本地缓存ehcache
java·spring boot·缓存·ehcache·ehcache持久化
weixin_7042660517 小时前
Spring Cloud Gateway
spring boot
lclcooky18 小时前
Spring Boot 整合 Keycloak
java·spring boot·后端
William Dawson19 小时前
【一文吃透 Spring Boot 面向切面编程(AOP):实例\+实现\+注意事项】
java·spring boot