Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
c55486d5
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 搜索 >>
提交
c55486d5
编写于
5月 31, 2015
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce alias for 'value' attribute in @RequestPart
Issue: SPR-11393
上级
034e0e2c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
13 deletion
+24
-13
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestPart.java
.../org/springframework/web/bind/annotation/RequestPart.java
+18
-6
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java
.../method/annotation/RequestPartMethodArgumentResolver.java
+4
-4
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java
...et/mvc/method/annotation/RequestPartIntegrationTests.java
+2
-3
未找到文件。
spring-web/src/main/java/org/springframework/web/bind/annotation/RequestPart.java
浏览文件 @
c55486d5
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -23,6 +23,7 @@ import java.lang.annotation.Retention;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
org.springframework.core.annotation.AliasFor
;
import
org.springframework.core.convert.converter.Converter
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -30,7 +31,9 @@ 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. Supported method argument types include {@link MultipartFile}
* 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
...
...
@@ -50,6 +53,7 @@ import org.springframework.web.multipart.MultipartResolver;
*
* @author Rossen Stoyanchev
* @author Arjen Poutsma
* @author Sam Brannen
* @since 3.1
*
* @see RequestParam
...
...
@@ -61,15 +65,23 @@ import org.springframework.web.multipart.MultipartResolver;
public
@interface
RequestPart
{
/**
*
The name of the part in the "multipart/form-data" request to bind to
.
*
Alias for {@link #name}
.
*/
@AliasFor
(
attribute
=
"name"
)
String
value
()
default
""
;
/**
* The name of the part in the "multipart/form-data" request to bind to.
* @since 4.2
*/
@AliasFor
(
attribute
=
"value"
)
String
name
()
default
""
;
/**
* Whether the part is required.
* <p>Default is {@code true}, leading to an exception
thrown in case
*
of the part missing in the request. Switch this to {@code false}
*
if you prefer a {@code null} in case of the part
missing.
* <p>Default is {@code true}, leading to an exception
being thrown
*
in case the part is missing in the request. Switch this to
*
{@code false} if you prefer a {@code null} if the part is
missing.
*/
boolean
required
()
default
true
;
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java
浏览文件 @
c55486d5
...
...
@@ -188,8 +188,8 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
}
}
RequestPart
ann
=
parameter
.
getParameterAnnotation
(
RequestPart
.
class
);
boolean
isRequired
=
((
ann
==
null
||
ann
.
required
())
&&
!
optional
);
RequestPart
requestPart
=
parameter
.
getParameterAnnotation
(
RequestPart
.
class
);
boolean
isRequired
=
((
requestPart
==
null
||
requestPart
.
required
())
&&
!
optional
);
if
(
arg
==
null
&&
isRequired
)
{
throw
new
MissingServletRequestPartException
(
partName
);
...
...
@@ -209,8 +209,8 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
}
private
String
getPartName
(
MethodParameter
methodParam
)
{
RequestPart
ann
=
methodParam
.
getParameterAnnotation
(
RequestPart
.
class
);
String
partName
=
(
ann
!=
null
?
ann
.
valu
e
()
:
""
);
RequestPart
requestPart
=
methodParam
.
getParameterAnnotation
(
RequestPart
.
class
);
String
partName
=
(
requestPart
!=
null
?
requestPart
.
nam
e
()
:
""
);
if
(
partName
.
length
()
==
0
)
{
partName
=
methodParam
.
getParameterName
();
if
(
partName
==
null
)
{
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java
浏览文件 @
c55486d5
...
...
@@ -179,14 +179,13 @@ public class RequestPartIntegrationTests {
}
}
@SuppressWarnings
(
"unused"
)
@Controller
private
static
class
RequestPartTestController
{
@RequestMapping
(
value
=
"/test"
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"multipart/mixed"
,
"multipart/form-data"
})
public
ResponseEntity
<
Object
>
create
(
@RequestPart
(
"json-data"
)
TestData
testData
,
public
ResponseEntity
<
Object
>
create
(
@RequestPart
(
name
=
"json-data"
)
TestData
testData
,
@RequestPart
(
"file-data"
)
MultipartFile
file
,
@RequestPart
(
valu
e
=
"empty-data"
,
required
=
false
)
TestData
emptyData
)
{
@RequestPart
(
nam
e
=
"empty-data"
,
required
=
false
)
TestData
emptyData
)
{
String
url
=
"http://localhost:8080/test/"
+
testData
.
getName
()
+
"/"
+
file
.
getOriginalFilename
();
HttpHeaders
headers
=
new
HttpHeaders
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录