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

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

相关推荐
xuhaoyu_cpp_java2 小时前
SpringBoot学习(四)
java·经验分享·spring boot·笔记·学习
不平衡的叉叉树6 小时前
Springboot+Mockito简单使用单元测试
java·spring boot·单元测试
山东点狮信息科技有限公司6 小时前
企业级开源OA系统推荐
vue.js·spring boot·性能优化·系统架构·开源
万亿少女的梦1687 小时前
基于Spring Boot与MySQL的乡镇群众服务系统设计与实现
java·spring boot·mysql·权限管理·前后端分离
杨运交10 小时前
[049][Crypto模块]前后端混合加密API实战:基于Spring Boot的AES+RSA安全传输方案
spring boot·后端·安全
William Dawson10 小时前
【国产化改造实战|Spring Boot对接华为云MRS Redis Kerberos认证终极踩坑指南】
spring boot·redis·华为云
宠友信息11 小时前
消息撤回与已读状态如何在即时通讯源码中统一管理
java·spring boot·websocket·mysql·uni-app
小小放舟、11 小时前
Windows 本地安装 Elasticsearch 8.10.0 与 IK 分词器(2026)
java·大数据·windows·spring boot·elasticsearch·搜索引擎·全文检索
半夜修仙11 小时前
Spring集成邮箱功能
java·开发语言·spring boot·spring·rabbitmq·github·maven
宠友信息12 小时前
从重复请求到订单同步看内容社区源码的处理思路
java·spring boot·redis·后端·mysql·spring