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 SummaryModifier and TypeMethodDescriptionvoidapplyArgumentValidation(Object target, Method method, MethodParameter @Nullable [] parameters, @Nullable Object[] arguments, Class<?>[] groups) Delegate toMethodValidator.validateArguments(Object, Method, MethodParameter[], Object[], Class[])and handle the validation result, by default raisingMethodValidationExceptionin case of errors.voidapplyReturnValueValidation(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Delegate toMethodValidator.validateReturnValue(Object, Method, MethodParameter, Object, Class[])and handle the validation result, by default raisingMethodValidationExceptionin case of errors.Class<?>[]determineValidationGroups(Object target, Method method) Determine the applicable validation groups.static @Nullable MethodValidatorfrom(@Nullable WebBindingInitializer initializer, @Nullable ParameterNameDiscoverer paramNameDiscoverer, Predicate<MethodParameter> modelAttributePredicate, 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 @Nullable [] parameters, @Nullable Object[] arguments, Class<?>[] groups) Validate the given method arguments and return validation results.validateReturnValue(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Validate the given return value and return validation results.
- 
Method Details- 
determineValidationGroupsDescription copied from interface:MethodValidatorDetermine the applicable validation groups. By default, obtained from an@Validatedannotation on the method, or on the class level.- Specified by:
- determineValidationGroupsin interface- MethodValidator
- Parameters:
- target- the target Object
- method- the target method
- Returns:
- the applicable validation groups as a Classarray
 
- 
applyArgumentValidationpublic void applyArgumentValidation(Object target, Method method, MethodParameter @Nullable [] parameters, @Nullable Object[] arguments, Class<?>[] groups) Description copied from interface:MethodValidatorDelegate toMethodValidator.validateArguments(Object, Method, MethodParameter[], Object[], Class[])and handle the validation result, by default raisingMethodValidationExceptionin case of errors. Implementations may provide alternative handling, for example, injectingErrorsinto the method.- Specified by:
- applyArgumentValidationin interface- MethodValidator
 
- 
validateArgumentspublic MethodValidationResult validateArguments(Object target, Method method, MethodParameter @Nullable [] parameters, @Nullable Object[] arguments, Class<?>[] groups) Description copied from interface:MethodValidatorValidate the given method arguments and return validation results.- Specified by:
- validateArgumentsin interface- MethodValidator
- Parameters:
- target- the target Object
- method- the target method
- parameters- the parameters, if already created and available
- arguments- the candidate argument values to validate
- groups- validation groups from- MethodValidator.determineValidationGroups(Object, Method)
- Returns:
- the result of validation
 
- 
applyReturnValueValidationpublic void applyReturnValueValidation(Object target, Method method, @Nullable MethodParameter returnType, @Nullable Object returnValue, Class<?>[] groups) Description copied from interface:MethodValidatorDelegate toMethodValidator.validateReturnValue(Object, Method, MethodParameter, Object, Class[])and handle the validation result, by default raisingMethodValidationExceptionin case of errors. Implementations may provide alternative handling.- Specified by:
- applyReturnValueValidationin interface- MethodValidator
 
- 
validateReturnValuepublic 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 validation results.- Specified by:
- validateReturnValuein interface- MethodValidator
- Parameters:
- target- the target Object
- method- the target method
- returnType- the return parameter, if already created and available
- returnValue- the return value to validate
- groups- validation groups from- MethodValidator.determineValidationGroups(Object, Method)
- Returns:
- the result of validation
 
- 
frompublic static @Nullable MethodValidator from(@Nullable WebBindingInitializer initializer, @Nullable ParameterNameDiscoverer paramNameDiscoverer, Predicate<MethodParameter> modelAttributePredicate, Predicate<MethodParameter> requestParamPredicate) Static factory method to create aHandlerMethodValidatorwhen Bean Validation is enabled for use viaConfigurableWebBindingInitializer, for example in Spring MVC or WebFlux config.
 
-