Tôi đang cố thêm tính năng tải ảnh lên ứng dụng mvc mùa xuân của mình.Tham số MultipartFile bắt buộc 'tệp' không có trong mùa xuân mvc
jsp phần:
...
<form method="POST" action="uploadImage" enctype="multipart/form-data">
<div class="load-line">
<input type="file" class="file"/>
<input type="submit" value="Upload">
...
cấu hình:
...
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
...
điều khiển:
@RequestMapping(value="/member/createCompany/uploadImage", method=RequestMethod.POST)
public @ResponseBody String handleFileUpload(
@RequestParam("file") MultipartFile file){
String name = "image_name";
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File(name + "-uploaded")));
stream.write(bytes);
stream.close();
return "You successfully uploaded " + name + " into " + name + "-uploaded !";
} catch (Exception e) {
return "You failed to upload " + name + " => " + e.getMessage();
}
} else {
return "You failed to upload " + name + " because the file was empty.";
}
}
Sau khi tôi chọn hình ảnh tôi bấm tải lên và thấy thông báo lỗi:
HTTP Status 400 - Required MultipartFile parameter 'file' is not present
Tôi làm gì sai?
hi bạn có thể gửi cho tôi mã đầy đủ xin vui lòng là phải đối mặt với cùng một [email protected] đây là id thư của tôi –