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

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

相关推荐
2601_953720825 小时前
【计算机毕业设计】基于Vue与Spring Boot的高校兼职信息服务平台设计与实现
spring boot·后端·课程设计
evans在进步7 小时前
Spring Boot 核心机制详解:可执行 JAR、CORS、静态资源与配置绑定
spring boot·后端·jar
Sayuanni%37 小时前
SpringBoot 从注解到源码:核心知识点总结
java·spring boot·后端
m0_587383009 小时前
社区家政系统开发实战:从需求分析到上线部署全指南
java·spring boot·spring·需求分析
凤山老林9 小时前
动态 i18n 体系落地:Spring Boot 多租户热加载与前后端协同实践
java·spring boot·后端·i18n
【赫兹威客】浩哥10 小时前
基于SpringBoot+Vue3的健身运动管理系统|WebSocket实时消息 健身房毕设项目
spring boot·websocket·课程设计
凤山老林10 小时前
数据库读写分离与动态路由实战:Spring Boot + ShardingSphere-JDBC 生产配置
数据库·spring boot·后端·分库分表·sharding-jdbc
RuoyiOffice11 小时前
SpringBoot3+Vue3 代码生成器深拆:元数据 IR、模板编译与安全同步
spring boot·vue3·mybatis plus·代码生成器·spring boot 3·velocity·元数据驱动
paopaokaka_luck12 小时前
基于springboot3+vue3的支教志愿者管理系统(AI问答、协同过滤算法、Echarts图形化分析)
spring boot·echarts
2601_9638701813 小时前
【计算机毕业设计】基于Vue+Spring Boot的助农电商系统的设计与实现
spring boot·后端·课程设计