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

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

相关推荐
Lucky GGBond3 小时前
Vue + Spring Boot 实现 Excel 导出实例
vue.js·spring boot·excel
seven97_top3 小时前
Springboot 常见面试题汇总
java·spring boot·后端
瑶山6 小时前
社区版Idea怎么创建Spring Boot项目?Selected Java version 17 is not supported. 问题解决
java·spring boot·intellij-idea·创建项目
陈小桔6 小时前
SpringBoot之配置文件
spring boot
智能化咨询7 小时前
基于Spring Boot + Vue 3的乡村振兴综合服务平台性能优化与扩展实践
vue.js·spring boot·性能优化
Hoking7 小时前
LangChain4j集成SpringBoot接入百炼大模型(Qwen)
java·人工智能·spring boot·llm
编啊编程啊程10 小时前
【004】生菜阅读平台
java·spring boot·spring cloud·dubbo·nio
椎49510 小时前
web后端开发——原理
spring boot·spring·mybatis
岁岁岁平安10 小时前
Java+SpringBoot+Dubbo+Nacos快速入门
java·spring boot·nacos·rpc·dubbo
小咕聊编程12 小时前
【含文档+PPT+源码】基于springboot的旅游路线推荐系统的设计与实现
spring boot·后端·旅游