Class HandlerMethodValidator
java.lang.Object
org.springframework.web.method.annotation.HandlerMethodValidator
- All Implemented Interfaces:
MethodValidator
MethodValidator
that
uses Bean Validation to validate @RequestMapping
method arguments.
Handles validation results by populating BindingResult
method
arguments with errors from beanResults
. Also, helps to determine parameter names for
@ModelAttribute
and @RequestBody
parameters.
- Since:
- 6.1
- Author:
- Rossen Stoyanchev
-
Method Summary
Modifier and TypeMethodDescriptionvoid
applyArgumentValidation
(Object target, Method method, MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Validate the given method arguments and handle the result.void
applyReturnValueValidation
(Object target, Method method, MethodParameter returnType, Object returnValue, Class<?>[] groups) Validate the given return value and handle the results.Class<?>[]
determineValidationGroups
(Object target, Method method) Use this method to determine the validation groups.static MethodValidator
from
(WebBindingInitializer initializer, ParameterNameDiscoverer paramNameDiscoverer, Predicate<MethodParameter> modelAttribitePredicate, Predicate<MethodParameter> requestParamPredicate) Static factory method to create aHandlerMethodValidator
when Bean Validation is enabled for use viaConfigurableWebBindingInitializer
, for example in Spring MVC or WebFlux config.validateArguments
(Object target, Method method, MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Validate the given method arguments and return validation results.validateReturnValue
(Object target, Method method, MethodParameter returnType, Object returnValue, Class<?>[] groups) Validate the given return value and return the result of validation.
-
Method Details
-
determineValidationGroups
Description copied from interface:MethodValidator
Use this method to determine the validation groups.- Specified by:
determineValidationGroups
in interfaceMethodValidator
- Parameters:
target
- the target Objectmethod
- the target method- Returns:
- the applicable validation groups as a
Class
array
-
applyArgumentValidation
public void applyArgumentValidation(Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Description copied from interface:MethodValidator
Validate the given method arguments and handle the result.- Specified by:
applyArgumentValidation
in interfaceMethodValidator
- Parameters:
target
- the target Objectmethod
- the target methodparameters
- the parameters, if already created and availablearguments
- the candidate argument values to validategroups
- validation groups viaMethodValidator.determineValidationGroups(java.lang.Object, java.lang.reflect.Method)
-
validateArguments
public MethodValidationResult validateArguments(Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Description copied from interface:MethodValidator
Validate the given method arguments and return validation results.- Specified by:
validateArguments
in interfaceMethodValidator
- Parameters:
target
- the target Objectmethod
- the target methodparameters
- the parameters, if already created and availablearguments
- the candidate argument values to validategroups
- validation groups fromMethodValidator.determineValidationGroups(java.lang.Object, java.lang.reflect.Method)
- Returns:
- the result of validation
-
applyReturnValueValidation
public void applyReturnValueValidation(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Description copied from interface:MethodValidator
Validate the given return value and handle the results.- Specified by:
applyReturnValueValidation
in interfaceMethodValidator
- Parameters:
target
- the target Objectmethod
- the target methodreturnType
- the return parameter, if already created and availablereturnValue
- the return value to validategroups
- validation groups fromMethodValidator.determineValidationGroups(java.lang.Object, java.lang.reflect.Method)
-
validateReturnValue
public MethodValidationResult validateReturnValue(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Description copied from interface:MethodValidator
Validate the given return value and return the result of validation.- Specified by:
validateReturnValue
in interfaceMethodValidator
- Parameters:
target
- the target Objectmethod
- the target methodreturnType
- the return parameter, if already created and availablereturnValue
- the return value to validategroups
- validation groups fromMethodValidator.determineValidationGroups(java.lang.Object, java.lang.reflect.Method)
- Returns:
- the result of validation
-
from
@Nullable public static MethodValidator from(@Nullable WebBindingInitializer initializer, @Nullable ParameterNameDiscoverer paramNameDiscoverer, Predicate<MethodParameter> modelAttribitePredicate, Predicate<MethodParameter> requestParamPredicate) Static factory method to create aHandlerMethodValidator
when Bean Validation is enabled for use viaConfigurableWebBindingInitializer
, for example in Spring MVC or WebFlux config.
-