formData
var file= document
.
querySelector
('
input[name = "file"]'
).files;
var fd = new FormData();
fd.append("files",file[0]);
springMVC接收参数加注解:
public void doSomething(@RequestParam
(
"file"
) MultipartFile
file){
}
需配置文件解析器
<bean
id
=
"multipartResolver"
class
=
"org.springframework.web.multipart.commons.CommonsMultipartResolver"
>
<!-- 上传文件大小上限,单位为字节(10MB) -->
<property
name
=
"maxUploadSize"
>
<value
>
10485760
</value
>
</property
>
<!-- 请求的编码格式,必须和jSP的pageEncoding属性一致,以便正确读取表单的内容,默认为ISO-8859-1 -->
<property
name
=
"defaultEncoding"
>
<value
>
UTF-8
</value
>
</property
>
</bean
>