Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sesemomo
spring-framework
提交
217aa38c
S
spring-framework
项目概览
sesemomo
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
217aa38c
编写于
8月 02, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
2474c487
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
11 deletion
+13
-11
spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java
...rk/web/method/annotation/InitBinderDataBinderFactory.java
+9
-7
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java
...ve/result/method/annotation/InitBinderBindingContext.java
+4
-4
未找到文件。
spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java
浏览文件 @
217aa38c
...
...
@@ -53,11 +53,13 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory {
this
.
binderMethods
=
(
binderMethods
!=
null
?
binderMethods
:
Collections
.
emptyList
());
}
/**
* Initialize a WebDataBinder with {@code @InitBinder} methods.
* <p>If the {@code @InitBinder} annotation specifies attributes names,
* it is invoked only if the names include the target object name.
* @throws Exception if one of the invoked @{@link InitBinder} methods fail.
* @throws Exception if one of the invoked @{@link InitBinder} methods fails
* @see #isBinderMethodApplicable
*/
@Override
public
void
initBinder
(
WebDataBinder
dataBinder
,
NativeWebRequest
request
)
throws
Exception
{
...
...
@@ -66,19 +68,19 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory {
Object
returnValue
=
binderMethod
.
invokeForRequest
(
request
,
null
,
dataBinder
);
if
(
returnValue
!=
null
)
{
throw
new
IllegalStateException
(
"@InitBinder methods
should return void
: "
+
binderMethod
);
"@InitBinder methods
must not return a value (should be void)
: "
+
binderMethod
);
}
}
}
}
/**
*
Whether the given {@code @InitBinder} method should be used to initialize
* t
he given WebDataBinder instance. By default we check the attributes
*
names of the annotation, if present
.
*
Determine whether the given {@code @InitBinder} method should be used
* t
o initialize the given {@link WebDataBinder} instance. By default we
*
check the specified attribute names in the annotation value, if any
.
*/
protected
boolean
isBinderMethodApplicable
(
HandlerMethod
b
inderMethod
,
WebDataBinder
dataBinder
)
{
InitBinder
ann
=
b
inderMethod
.
getMethodAnnotation
(
InitBinder
.
class
);
protected
boolean
isBinderMethodApplicable
(
HandlerMethod
initB
inderMethod
,
WebDataBinder
dataBinder
)
{
InitBinder
ann
=
initB
inderMethod
.
getMethodAnnotation
(
InitBinder
.
class
);
Assert
.
state
(
ann
!=
null
,
"No InitBinder annotation"
);
String
[]
names
=
ann
.
value
();
return
(
ObjectUtils
.
isEmpty
(
names
)
||
ObjectUtils
.
containsElement
(
names
,
dataBinder
.
getObjectName
()));
...
...
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java
浏览文件 @
217aa38c
...
...
@@ -83,18 +83,18 @@ class InitBinderBindingContext extends BindingContext {
return
dataBinder
;
}
private
void
invokeBinderMethod
(
WebExchangeDataBinder
dataBinder
,
ServerWebExchange
exchange
,
SyncInvocableHandlerMethod
binderMethod
)
{
private
void
invokeBinderMethod
(
WebExchangeDataBinder
dataBinder
,
ServerWebExchange
exchange
,
SyncInvocableHandlerMethod
binderMethod
)
{
HandlerResult
result
=
binderMethod
.
invokeForHandlerResult
(
exchange
,
this
.
binderMethodContext
,
dataBinder
);
if
(
result
!=
null
&&
result
.
getReturnValue
()
!=
null
)
{
throw
new
IllegalStateException
(
"@InitBinder methods
should return void
: "
+
binderMethod
);
"@InitBinder methods
must not return a value (should be void)
: "
+
binderMethod
);
}
// Should not happen (no Model argument resolution) ...
if
(!
this
.
binderMethodContext
.
getModel
().
asMap
().
isEmpty
())
{
throw
new
IllegalStateException
(
"@InitBinder methods
should not
add model attributes: "
+
binderMethod
);
"@InitBinder methods
are not allowed to
add model attributes: "
+
binderMethod
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录