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 TypeMethodDescriptionvoidapplyArgumentValidation(Object target, Method method, MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Validate the given method arguments and handle the result.voidapplyReturnValueValidation(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 MethodValidatorfrom(WebBindingInitializer initializer, ParameterNameDiscoverer paramNameDiscoverer, Predicate<MethodParameter> modelAttribitePredicate, Predicate<MethodParameter> requestParamPredicate) Static factory method to create aHandlerMethodValidatorwhen 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:MethodValidatorUse this method to determine the validation groups.- Specified by:
determineValidationGroupsin interfaceMethodValidator- Parameters:
target- the target Objectmethod- the target method- Returns:
- the applicable validation groups as a
Classarray
-
applyArgumentValidation
public void applyArgumentValidation(Object target, Method method, @Nullable MethodParameter[] parameters, Object[] arguments, Class<?>[] groups) Description copied from interface:MethodValidatorValidate the given method arguments and handle the result.- Specified by:
applyArgumentValidationin 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:MethodValidatorValidate the given method arguments and return validation results.- Specified by:
validateArgumentsin 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:MethodValidatorValidate the given return value and handle the results.- Specified by:
applyReturnValueValidationin 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:MethodValidatorValidate the given return value and return the result of validation.- Specified by:
validateReturnValuein 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 aHandlerMethodValidatorwhen Bean Validation is enabled for use viaConfigurableWebBindingInitializer, for example in Spring MVC or WebFlux config.
-