0
点赞
收藏
分享

微信扫一扫

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

星巢文化 2024-06-02 阅读 31
spring boot

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

举报

相关推荐

0 条评论