Controller
@Slf4j
@Controller
public class FormController {
//th:href="@{/upload}
@GetMapping("upload")
public String form(){
return "form/upload";
}
//th:action="@{/upload}
@PostMapping("upload")
public String upload(@RequestParam("email") String email,
@RequestParam("username") String username,
@RequestPart("headerImg")MultipartFile headerImg,
@RequestPart("photos") MultipartFile[] photos) throws IOException {
log.info("上传的文件信息,email={},username={},HeaderImg={},photos={}",
email,username,headerImg.getSize(),photos.length);
if (!headerImg.isEmpty()){
String originalFilename = headerImg.getOriginalFilename();
headerImg.transferTo(new File("D:\"+originalFilename));
}
return "dashboard";
}
}
form
配置文件
spring.servlet.multipart.max-file-size=30MB
spring.servlet.multipart.max-request-size=50MB