Polishing

This commit is contained in:
Juergen Hoeller
2018-10-24 20:46:26 +02:00
parent f0f1979fc5
commit ffa032e78f
9 changed files with 49 additions and 60 deletions

View File

@@ -33,23 +33,24 @@ import org.springframework.web.multipart.MultipartResolver;
* Annotation that can be used to associate the part of a "multipart/form-data" request
* with a method argument.
*
* <p>Supported method argument types include {@link MultipartFile}
* in conjunction with Spring's {@link MultipartResolver} abstraction,
* {@code javax.servlet.http.Part} in conjunction with Servlet 3.0 multipart requests,
* or otherwise for any other method argument, the content of the part is passed through an
* {@link HttpMessageConverter} taking into consideration the 'Content-Type' header
* of the request part. This is analogous to what @{@link RequestBody} does to resolve
* an argument based on the content of a non-multipart regular request.
* <p>Supported method argument types include {@link MultipartFile} in conjunction with
* Spring's {@link MultipartResolver} abstraction, {@code javax.servlet.http.Part} in
* conjunction with Servlet 3.0 multipart requests, or otherwise for any other method
* argument, the content of the part is passed through an {@link HttpMessageConverter}
* taking into consideration the 'Content-Type' header of the request part. This is
* analogous to what @{@link RequestBody} does to resolve an argument based on the
* content of a non-multipart regular request.
*
* <p>Note that @{@link RequestParam} annotation can also be used to associate the
* part of a "multipart/form-data" request with a method argument supporting the same
* method argument types. The main difference is that when the method argument is not a
* String, @{@link RequestParam} relies on type conversion via a registered
* {@link Converter} or {@link PropertyEditor} while @{@link RequestPart} relies
* on {@link HttpMessageConverter HttpMessageConverters} taking into consideration the 'Content-Type' header
* of the request part. @{@link RequestParam} is likely to be used with name-value form
* fields while @{@link RequestPart} is likely to be used with parts containing more
* complex content (e.g. JSON, XML).
* <p>Note that @{@link RequestParam} annotation can also be used to associate the part
* of a "multipart/form-data" request with a method argument supporting the same method
* argument types. The main difference is that when the method argument is not a String
* or raw {@code MultipartFile} / {@code Part}, {@code @RequestParam} relies on type
* conversion via a registered {@link Converter} or {@link PropertyEditor} while
* {@link RequestPart} relies on {@link HttpMessageConverter HttpMessageConverters}
* taking into consideration the 'Content-Type' header of the request part.
* {@link RequestParam} is likely to be used with name-value form fields while
* {@link RequestPart} is likely to be used with parts containing more complex content
* e.g. JSON, XML).
*
* @author Rossen Stoyanchev
* @author Arjen Poutsma

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

View File

@@ -41,7 +41,7 @@ import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.UriComponentsContributor;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartRequest;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.MissingServletRequestPartException;
import org.springframework.web.multipart.support.MultipartResolutionDelegate;
@@ -114,15 +114,11 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
* Supports the following:
* <ul>
* <li>@RequestParam-annotated method arguments.
* This excludes {@link Map} params where the annotation doesn't
* specify a name. See {@link RequestParamMapMethodArgumentResolver}
* instead for such params.
* <li>Arguments of type {@link MultipartFile}
* unless annotated with @{@link RequestPart}.
* <li>Arguments of type {@code javax.servlet.http.Part}
* unless annotated with @{@link RequestPart}.
* <li>In default resolution mode, simple type arguments
* even if not with @{@link RequestParam}.
* This excludes {@link Map} params where the annotation does not specify a name.
* See {@link RequestParamMapMethodArgumentResolver} instead for such params.
* <li>Arguments of type {@link MultipartFile} unless annotated with @{@link RequestPart}.
* <li>Arguments of type {@code Part} unless annotated with @{@link RequestPart}.
* <li>In default resolution mode, simple type arguments even if not with @{@link RequestParam}.
* </ul>
*/
@Override
@@ -172,7 +168,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
}
Object arg = null;
MultipartHttpServletRequest multipartRequest = request.getNativeRequest(MultipartHttpServletRequest.class);
MultipartRequest multipartRequest = request.getNativeRequest(MultipartRequest.class);
if (multipartRequest != null) {
List<MultipartFile> files = multipartRequest.getFiles(name);
if (!files.isEmpty()) {