스프링 MVC는 전달되는 파라미터가 동일한 이름으로 여러 개 존재하면 배열로 처리가 가능
예제
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action = "/sample/exUploadPost" method="post"
enctype="multipart/form-data">
<div>
<input type="file" name="files">
</div>
<div>
<input type="file" name="files">
</div>
<div>
<input type="file" name="files">
</div>
<div>
<input type="file" name="files">
</div>
<div>
<input type="file" name="files">
</div>
<div>
<input type="submit">
</div>
</form>
</body>
</html>
@PostMapping("/exUploadPost")
public void exUploadPost(ArrayList<MultipartFile> files) {
files.forEach(file -> {
log.info("---------------------");
log.info("name: " + file.getOriginalFilename());
log.info("size: " + file.getSize());
});
}
'spring' 카테고리의 다른 글
스프링 MVC 프로젝트의 기본 구성, 비즈니스 계층 spring core 설정에서의 scan, 등록/수정/삭제 시 redirect를 하는 이유 (0) | 2024.02.18 |
---|---|
@Override 쓰는 이유 (0) | 2023.06.02 |
Controller의 리턴 타입 (0) | 2023.02.21 |
Model이라는 데이터 전달자 (0) | 2023.02.17 |
@DateTimeFormat (0) | 2023.02.17 |