提交 217aa38c 编写于 作者: J Juergen Hoeller

Polishing

上级 2474c487
......@@ -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
* the 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
* to initialize the given {@link WebDataBinder} instance. By default we
* check the specified attribute names in the annotation value, if any.
*/
protected boolean isBinderMethodApplicable(HandlerMethod binderMethod, WebDataBinder dataBinder) {
InitBinder ann = binderMethod.getMethodAnnotation(InitBinder.class);
protected boolean isBinderMethodApplicable(HandlerMethod initBinderMethod, WebDataBinder dataBinder) {
InitBinder ann = initBinderMethod.getMethodAnnotation(InitBinder.class);
Assert.state(ann != null, "No InitBinder annotation");
String[] names = ann.value();
return (ObjectUtils.isEmpty(names) || ObjectUtils.containsElement(names, dataBinder.getObjectName()));
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册