Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
ffa032e7
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ffa032e7
编写于
10月 24, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
f0f1979f
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
49 addition
and
60 deletion
+49
-60
spring-core/src/main/java/org/springframework/util/MultiValueMap.java
...src/main/java/org/springframework/util/MultiValueMap.java
+1
-1
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestPart.java
.../org/springframework/web/bind/annotation/RequestPart.java
+17
-16
spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java
...ngframework/web/method/annotation/MapMethodProcessor.java
+2
-2
spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java
...method/annotation/RequestParamMethodArgumentResolver.java
+7
-11
spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java
...notation/RequestHeaderMapMethodArgumentResolverTests.java
+1
-1
spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolverTests.java
.../annotation/RequestHeaderMethodArgumentResolverTests.java
+3
-3
spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java
...d/annotation/RequestParamMethodArgumentResolverTests.java
+13
-22
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java
...rvlet/mvc/annotation/ResponseStatusExceptionResolver.java
+4
-3
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java
.../method/annotation/RequestPartMethodArgumentResolver.java
+1
-1
未找到文件。
spring-core/src/main/java/org/springframework/util/MultiValueMap.java
浏览文件 @
ffa032e7
...
...
@@ -75,7 +75,7 @@ public interface MultiValueMap<K, V> extends Map<K, List<V>> {
void
setAll
(
Map
<
K
,
V
>
values
);
/**
* Return
s
the first values contained in this {@code MultiValueMap}.
* Return
a {@code Map} with
the first values contained in this {@code MultiValueMap}.
* @return a single value representation of this map
*/
Map
<
K
,
V
>
toSingleValueMap
();
...
...
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestPart.java
浏览文件 @
ffa032e7
...
...
@@ -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 resolv
e
*
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 th
e
* 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
...
...
spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java
浏览文件 @
ffa032e7
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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
{
...
...
spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java
浏览文件 @
ffa032e7
...
...
@@ -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.Multipart
HttpServlet
Request
;
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
;
Multipart
HttpServletRequest
multipartRequest
=
request
.
getNativeRequest
(
MultipartHttpServle
tRequest
.
class
);
Multipart
Request
multipartRequest
=
request
.
getNativeRequest
(
Multipar
tRequest
.
class
);
if
(
multipartRequest
!=
null
)
{
List
<
MultipartFile
>
files
=
multipartRequest
.
getFiles
(
name
);
if
(!
files
.
isEmpty
())
{
...
...
spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolverTests.java
浏览文件 @
ffa032e7
...
...
@@ -60,7 +60,7 @@ public class RequestHeaderMapMethodArgumentResolverTests {
@Before
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
resolver
=
new
RequestHeaderMapMethodArgumentResolver
();
Method
method
=
getClass
().
getMethod
(
"params"
,
Map
.
class
,
MultiValueMap
.
class
,
HttpHeaders
.
class
,
Map
.
class
);
...
...
spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolverTests.java
浏览文件 @
ffa032e7
...
...
@@ -44,7 +44,7 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
import
static
org
.
junit
.
Assert
.*;
/**
* Test fixture with {@link
org.springframework.web.method.annotation.
RequestHeaderMethodArgumentResolver}.
* Test fixture with {@link RequestHeaderMethodArgumentResolver}.
*
* @author Arjen Poutsma
* @author Rossen Stoyanchev
...
...
@@ -70,7 +70,7 @@ public class RequestHeaderMethodArgumentResolverTests {
@Before
@SuppressWarnings
(
"resource"
)
public
void
set
U
p
()
throws
Exception
{
public
void
set
u
p
()
throws
Exception
{
GenericWebApplicationContext
context
=
new
GenericWebApplicationContext
();
context
.
refresh
();
resolver
=
new
RequestHeaderMethodArgumentResolver
(
context
.
getBeanFactory
());
...
...
@@ -94,7 +94,7 @@ public class RequestHeaderMethodArgumentResolverTests {
}
@After
public
void
teardown
()
{
public
void
reset
()
{
RequestContextHolder
.
resetRequestAttributes
();
}
...
...
spring-web/src/test/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolverTests.java
浏览文件 @
ffa032e7
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
8
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.
...
...
@@ -22,7 +22,6 @@ import java.util.Map;
import
java.util.Optional
;
import
javax.servlet.http.Part
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.beans.propertyeditors.StringTrimmerEditor
;
...
...
@@ -53,7 +52,7 @@ import static org.mockito.BDDMockito.*;
import
static
org
.
springframework
.
web
.
method
.
MvcAnnotationPredicates
.*;
/**
* Test fixture with {@link
org.springframework.web.method.annotation.
RequestParamMethodArgumentResolver}.
* Test fixture with {@link RequestParamMethodArgumentResolver}.
*
* @author Arjen Poutsma
* @author Rossen Stoyanchev
...
...
@@ -61,23 +60,15 @@ import static org.springframework.web.method.MvcAnnotationPredicates.*;
*/
public
class
RequestParamMethodArgumentResolverTests
{
private
RequestParamMethodArgumentResolver
resolver
;
private
RequestParamMethodArgumentResolver
resolver
=
new
RequestParamMethodArgumentResolver
(
null
,
true
)
;
private
NativeWebRequest
webRequest
;
private
MockHttpServletRequest
request
=
new
MockHttpServletRequest
()
;
private
MockHttpServletRequest
request
;
private
NativeWebRequest
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
())
;
private
ResolvableMethod
testMethod
=
ResolvableMethod
.
on
(
getClass
()).
named
(
"handle"
).
build
();
@Before
public
void
setup
()
throws
Exception
{
resolver
=
new
RequestParamMethodArgumentResolver
(
null
,
true
);
request
=
new
MockHttpServletRequest
();
webRequest
=
new
ServletWebRequest
(
request
,
new
MockHttpServletResponse
());
}
@Test
public
void
supportsParameter
()
{
resolver
=
new
RequestParamMethodArgumentResolver
(
null
,
true
);
...
...
@@ -385,7 +376,7 @@ public class RequestParamMethodArgumentResolverTests {
WebDataBinderFactory
binderFactory
=
mock
(
WebDataBinderFactory
.
class
);
given
(
binderFactory
.
createBinder
(
webRequest
,
null
,
"stringNotAnnot"
)).
willReturn
(
binder
);
this
.
request
.
addParameter
(
"stringNotAnnot"
,
""
);
request
.
addParameter
(
"stringNotAnnot"
,
""
);
MethodParameter
param
=
this
.
testMethod
.
annotNotPresent
(
RequestParam
.
class
).
arg
(
String
.
class
);
Object
arg
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
binderFactory
);
...
...
@@ -400,7 +391,7 @@ public class RequestParamMethodArgumentResolverTests {
WebDataBinderFactory
binderFactory
=
mock
(
WebDataBinderFactory
.
class
);
given
(
binderFactory
.
createBinder
(
webRequest
,
null
,
"name"
)).
willReturn
(
binder
);
this
.
request
.
addParameter
(
"name"
,
""
);
request
.
addParameter
(
"name"
,
""
);
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestParam
().
notRequired
()).
arg
(
String
.
class
);
Object
arg
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
binderFactory
);
...
...
@@ -426,7 +417,7 @@ public class RequestParamMethodArgumentResolverTests {
@Test
// SPR-10180
public
void
resolveEmptyValueToDefault
()
throws
Exception
{
this
.
request
.
addParameter
(
"name"
,
""
);
request
.
addParameter
(
"name"
,
""
);
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestParam
().
notRequired
(
"bar"
)).
arg
(
String
.
class
);
Object
result
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
null
);
assertEquals
(
"bar"
,
result
);
...
...
@@ -434,7 +425,7 @@ public class RequestParamMethodArgumentResolverTests {
@Test
public
void
resolveEmptyValueWithoutDefault
()
throws
Exception
{
this
.
request
.
addParameter
(
"stringNotAnnot"
,
""
);
request
.
addParameter
(
"stringNotAnnot"
,
""
);
MethodParameter
param
=
this
.
testMethod
.
annotNotPresent
(
RequestParam
.
class
).
arg
(
String
.
class
);
Object
result
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
null
);
assertEquals
(
""
,
result
);
...
...
@@ -442,7 +433,7 @@ public class RequestParamMethodArgumentResolverTests {
@Test
public
void
resolveEmptyValueRequiredWithoutDefault
()
throws
Exception
{
this
.
request
.
addParameter
(
"name"
,
""
);
request
.
addParameter
(
"name"
,
""
);
MethodParameter
param
=
this
.
testMethod
.
annot
(
requestParam
().
notRequired
()).
arg
(
String
.
class
);
Object
result
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
null
);
assertEquals
(
""
,
result
);
...
...
@@ -459,7 +450,7 @@ public class RequestParamMethodArgumentResolverTests {
Object
result
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
binderFactory
);
assertEquals
(
Optional
.
empty
(),
result
);
this
.
request
.
addParameter
(
"name"
,
"123"
);
request
.
addParameter
(
"name"
,
"123"
);
result
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
binderFactory
);
assertEquals
(
Optional
.
class
,
result
.
getClass
());
assertEquals
(
123
,
((
Optional
)
result
).
get
());
...
...
@@ -492,7 +483,7 @@ public class RequestParamMethodArgumentResolverTests {
Object
result
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
binderFactory
);
assertEquals
(
Optional
.
empty
(),
result
);
this
.
request
.
addParameter
(
"name"
,
"123"
,
"456"
);
request
.
addParameter
(
"name"
,
"123"
,
"456"
);
result
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
binderFactory
);
assertEquals
(
Optional
.
class
,
result
.
getClass
());
assertArrayEquals
(
new
Integer
[]
{
123
,
456
},
(
Integer
[])
((
Optional
)
result
).
get
());
...
...
@@ -525,7 +516,7 @@ public class RequestParamMethodArgumentResolverTests {
Object
result
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
binderFactory
);
assertEquals
(
Optional
.
empty
(),
result
);
this
.
request
.
addParameter
(
"name"
,
"123"
,
"456"
);
request
.
addParameter
(
"name"
,
"123"
,
"456"
);
result
=
resolver
.
resolveArgument
(
param
,
null
,
webRequest
,
binderFactory
);
assertEquals
(
Optional
.
class
,
result
.
getClass
());
assertEquals
(
Arrays
.
asList
(
"123"
,
"456"
),
((
Optional
)
result
).
get
());
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java
浏览文件 @
ffa032e7
...
...
@@ -81,12 +81,13 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes
}
if
(
ex
.
getCause
()
instanceof
Exception
)
{
ex
=
(
Exception
)
ex
.
getCause
();
return
doResolveException
(
request
,
response
,
handler
,
ex
);
return
doResolveException
(
request
,
response
,
handler
,
(
Exception
)
ex
.
getCause
());
}
}
catch
(
Exception
resolveEx
)
{
logger
.
warn
(
"Failure while trying to resolve exception ["
+
ex
.
getClass
().
getName
()
+
"]"
,
resolveEx
);
if
(
logger
.
isWarnEnabled
())
{
logger
.
warn
(
"Failure while trying to resolve exception ["
+
ex
.
getClass
().
getName
()
+
"]"
,
resolveEx
);
}
}
return
null
;
}
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java
浏览文件 @
ffa032e7
...
...
@@ -43,7 +43,7 @@ import org.springframework.web.multipart.support.RequestPartServletServerHttpReq
/**
* Resolves the following method arguments:
* <ul>
* <li>Annotated with
{@code @
RequestPart}
* <li>Annotated with
@{@link
RequestPart}
* <li>Of type {@link MultipartFile} in conjunction with Spring's {@link MultipartResolver} abstraction
* <li>Of type {@code javax.servlet.http.Part} in conjunction with Servlet 3.0 multipart requests
* </ul>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录