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

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

相关推荐
一 乐10 小时前
医院挂号|基于springboot + vue医院挂号管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·医院挂号管理系统
better_liang11 小时前
每日Java面试场景题知识点之-MCP协议在Java开发中的应用实践
java·spring boot·ai·mcp·企业级开发
河阿里11 小时前
SpringBoot :使用 @Configuration 集中管理 Bean
java·spring boot·spring
Flittly11 小时前
【SpringSecurity新手村系列】(4)验证码功能实现
java·spring boot·安全·spring
MateCloud微服务13 小时前
懂你所需,利爪随行:MateClaw 正式开源,补齐 Java 生态的 AI Agent 拼图
spring boot·aigc·javaagent·aiagent·openclaw·mateclaw·javaclaw
是宇写的啊13 小时前
SpringBoot配置文件
java·spring boot·spring
虹梦未来16 小时前
【开发心得】在SpringBoot体系中正确使用redisConfig
java·spring boot·spring
user_admin_god17 小时前
OpenCode入门到入坑
java·人工智能·spring boot·语言模型
地瓜伯伯18 小时前
SpringBoot项目整合Elasticsearch启动失败的常见错误总结
spring boot·elasticsearch·spring cloud
霸道流氓气质19 小时前
SpringBoot中集成LangChain4j+阿里百炼平台实现AI对话记忆功能、对话隔离、对话持久化到Redis功能
人工智能·spring boot·redis