firefox

图片alt

图片alt

图片alt

图片alt

chrome

图片alt

图片alt

一个正确的例子

图片alt

图片alt

DispatcherServlet.java
protected void initStrategies(ApplicationContext context) {
		initMultipartResolver(context);
		.....
}
private void initMultipartResolver(ApplicationContext context) {
		try {
			//从Spring的上下文中获取id为multipartResolver的bean作为它的MutipartResolver
			this.multipartResolver = context.getBean(`multipartResolver`, MultipartResolver.class);
			if (logger.isTraceEnabled()) {
				logger.trace("Detected " + this.multipartResolver);
			}
			else if (logger.isDebugEnabled()) {
				logger.debug("Detected " + this.multipartResolver.getClass().getSimpleName());
			}
		}
		catch (NoSuchBeanDefinitionException ex) {
			// Default is no multipart resolver.
			this.multipartResolver = null;
			if (logger.isTraceEnabled()) {
				logger.trace("No MultipartResolver '" + MULTIPART_RESOLVER_BEAN_NAME + "' declared");
			}
		}
	}

待看源码

    @PostMapping(value = "/testUpload")
    public Attachment testUpload(String name, @RequestPart(required = false)MultipartFile file2){
        if(file2!=null){
            return  attachmentService.upload(file2);
        }
        return new Attachment();
    }

https://github.com/wangyang1749/shope_base_servlert/blob/master/src/com/shop/servlet/MultipartRequestWrapper.java

springmvc多文件上传

 <form action="http://localhost:8080/api/template/upload" method="post"  enctype="multipart/form-data">  
        <p>选择文件:<input type="file" name="file"></p>
        <p>选择文件:<input type="file" name="file"></p>
        <p><input type="submit" value="提交"></p>
    </form>  
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @Anonymous
    public Attachment upload(@RequestPart("file") MultipartFile[] file){
        return  null;
    }

参考:
https://blog.csdn.net/suifeng3051/article/details/51659731
https://blog.csdn.net/suifeng3051/article/details/51659731