Polishing
This commit is contained in:
@@ -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.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.web.method.annotation;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -57,15 +55,15 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory {
|
||||
|
||||
/**
|
||||
* Initialize a WebDataBinder with {@code @InitBinder} methods.
|
||||
* If the {@code @InitBinder} annotation specifies attributes names, it is
|
||||
* invoked only if the names include the target object name.
|
||||
* <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.
|
||||
*/
|
||||
@Override
|
||||
public void initBinder(WebDataBinder binder, NativeWebRequest request) throws Exception {
|
||||
public void initBinder(WebDataBinder dataBinder, NativeWebRequest request) throws Exception {
|
||||
for (InvocableHandlerMethod binderMethod : this.binderMethods) {
|
||||
if (isBinderMethodApplicable(binderMethod, binder)) {
|
||||
Object returnValue = binderMethod.invokeForRequest(request, null, binder);
|
||||
if (isBinderMethodApplicable(binderMethod, dataBinder)) {
|
||||
Object returnValue = binderMethod.invokeForRequest(request, null, dataBinder);
|
||||
if (returnValue != null) {
|
||||
throw new IllegalStateException(
|
||||
"@InitBinder methods should return void: " + binderMethod);
|
||||
@@ -79,11 +77,11 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory {
|
||||
* the given WebDataBinder instance. By default we check the attributes
|
||||
* names of the annotation, if present.
|
||||
*/
|
||||
protected boolean isBinderMethodApplicable(HandlerMethod binderMethod, WebDataBinder binder) {
|
||||
protected boolean isBinderMethodApplicable(HandlerMethod binderMethod, WebDataBinder dataBinder) {
|
||||
InitBinder ann = binderMethod.getMethodAnnotation(InitBinder.class);
|
||||
Assert.state(ann != null, "No InitBinder annotation");
|
||||
String[] names = ann.value();
|
||||
return ObjectUtils.isEmpty(names) || Arrays.asList(names).contains(binder.getObjectName());
|
||||
return (ObjectUtils.isEmpty(names) || ObjectUtils.containsElement(names, dataBinder.getObjectName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user