<form method="post" enctype="multipart/form-data">
...
</form>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="104857600"/>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
pom.xml
Maven Repository에서 common fileupload를 검색해 dependency 입력
FileUploadController.java
@Controller
@RequestMapping("/bbs")
public class FileUploadController {
@PostMapping("/upload")
public String upload(@RequestParam("file") MultipartFile file,
@RequestParam("name") String fileNmae,
Model model) {
if(!file.isEmpty()) { // 파일 저장 완료
File f = new File("c://upload", file.getOriginalFilename());
file.transferTo(f);
}
model.addAttribute("fileName", fileName); // 실제파일 이름, 전달 데이터명
return "upload_ok";
{
}