org.springframework.validation.beanvalidation

## 类 SpringValidatorAdapter

- java.lang.Object
- - org.springframework.validation.beanvalidation.SpringValidatorAdapter

- 所有已实现的接口:
    Validator, SmartValidator
  直接已知子类:
    CustomValidatorBean, LocalValidatorFactoryBean

      public class SpringValidatorAdapter
      extends Object
      implements SmartValidator, Validator

  Adapter that takes a JSR-303 `javax.validator.Validator` and exposes it as a Spring `Validator` while also exposing the original JSR-303 Validator interface itself.

  Can be used as a programmatic wrapper. Also serves as base class for `CustomValidatorBean` and `LocalValidatorFactoryBean`, and as the primary implementation of the `SmartValidator` interface.

  As of Spring Framework 5.0, this adapter is fully compatible with Bean Validation 1.1 as well as 2.0.

  从以下版本开始:
    3.0
  作者:
    Juergen Hoeller
  另请参阅:
    `SmartValidator`, `CustomValidatorBean`, `LocalValidatorFactoryBean`

- - ### 构造器概要

    构造器
    构造器和说明
    `SpringValidatorAdapter(Validator targetValidator)` Create a new SpringValidatorAdapter for the given JSR-303 Validator.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected String` | `determineErrorCode(ConstraintDescriptor<?> descriptor)` Determine a Spring-reported error code for the given constraint descriptor.
    `protected String` | `determineField(ConstraintViolation<Object> violation)` Determine a field for the given constraint violation.
    `ExecutableValidator` | `forExecutables()`
    `protected Object[]` | `getArgumentsForConstraint(String objectName, String field, ConstraintDescriptor<?> descriptor)` Return FieldError arguments for a validation error on the given field.
    `BeanDescriptor` | `getConstraintsForClass(Class<?> clazz)`
    `protected Object` | `getRejectedValue(String field, ConstraintViolation<Object> violation, BindingResult bindingResult)` Extract the rejected value behind the given constraint violation, for exposure through the Spring errors representation.
    `protected MessageSourceResolvable` | `getResolvableField(String objectName, String field)` Build a resolvable wrapper for the specified field, allowing to resolve the field's name in a `MessageSource`.
    `protected void` | `processConstraintViolations(Set<ConstraintViolation<Object>> violations, Errors errors)` Process the given JSR-303 ConstraintViolations, adding corresponding errors to the provided Spring `Errors` object.
    `boolean` | `supports(Class<?> clazz)` Can this `Validator` `validate` instances of the supplied `clazz`?
    `<T> T` | `unwrap(Class<T> type)`
    `void` | `validate(Object target, Errors errors)` Validate the supplied `target` object, which must be of a `Class` for which the `Validator.supports(Class)` method typically has (or would) return `true`.
    `void` | `validate(Object target, Errors errors, Object... validationHints)` Validate the supplied `target` object, which must be of a type of `Class` for which the `Validator.supports(Class)` method typically returns `true`.
    `<T> Set<ConstraintViolation<T>>` | `validate(T object, Class<?>... groups)`
    `<T> Set<ConstraintViolation<T>>` | `validateProperty(T object, String propertyName, Class<?>... groups)`
    `<T> Set<ConstraintViolation<T>>` | `validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups)`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 构造器详细资料

    - #### SpringValidatorAdapter

          public SpringValidatorAdapter(Validator targetValidator)

      Create a new SpringValidatorAdapter for the given JSR-303 Validator.
      参数:
        `targetValidator` - the JSR-303 Validator to wrap

  - ### 方法详细资料

    - #### supports

          public boolean supports(Class<?> clazz)

      从接口复制的说明: `Validator`
      Can this `Validator` `validate` instances of the supplied `clazz`?

      This method is typically implemented like so:

          return Foo.class.isAssignableFrom(clazz);

      (Where `Foo` is the class (or superclass) of the actual object instance that is to be `validated`.)
      参数:
        `clazz` - the `Class` that this `Validator` is being asked if it can `validate`
      返回:
        `true` if this `Validator` can indeed `validate` instances of the supplied `clazz`

    - #### validate

          public void validate(@Nullable
                               Object target,
                               Errors errors)

      从接口复制的说明: `Validator`
      Validate the supplied `target` object, which must be of a `Class` for which the `Validator.supports(Class)` method typically has (or would) return `true`.

      The supplied `errors` instance can be used to report any resulting validation errors.

      参数:
        `target` - the object that is to be validated (can be `null`)
        `errors` - contextual state about the validation process (never `null`)
      另请参阅:
        `ValidationUtils`

    - #### validate

          public void validate(@Nullable
                               Object target,
                               Errors errors,
                               @Nullable
                               Object... validationHints)

      从接口复制的说明: `SmartValidator`
      Validate the supplied `target` object, which must be of a type of `Class` for which the `Validator.supports(Class)` method typically returns `true`.

      The supplied `errors` instance can be used to report any resulting validation errors.

      This variant of `validate()` supports validation hints, such as validation groups against a JSR-303 provider (in which case, the provided hint objects need to be annotation arguments of type `Class`).

      Note: Validation hints may get ignored by the actual target `Validator`, in which case this method should behave just like its regular `Validator.validate(Object, Errors)` sibling.

      指定者:
        `validate` 在接口中 `SmartValidator`
      参数:
        `target` - the object that is to be validated (can be `null`)
        `errors` - contextual state about the validation process (never `null`)
        `validationHints` - one or more hint objects to be passed to the validation engine
      另请参阅:
        `ValidationUtils`

    - #### processConstraintViolations

          protected void processConstraintViolations(Set<ConstraintViolation<Object>> violations,
                                                     Errors errors)

      Process the given JSR-303 ConstraintViolations, adding corresponding errors to the provided Spring `Errors` object.
      参数:
        `violations` - the JSR-303 ConstraintViolation results
        `errors` - the Spring errors object to register to

    - #### determineField

          protected String determineField(ConstraintViolation<Object> violation)

      Determine a field for the given constraint violation.

      The default implementation returns the stringified property path.

      参数:
        `violation` - the current JSR-303 ConstraintViolation
      返回:
        the Spring-reported field (for use with `Errors`)
      从以下版本开始:
        4.2
      另请参阅:
        `ConstraintViolation.getPropertyPath()`, `FieldError.getField()`

    - #### determineErrorCode

          protected String determineErrorCode(ConstraintDescriptor<?> descriptor)

      Determine a Spring-reported error code for the given constraint descriptor.

      The default implementation returns the simple class name of the descriptor's annotation type. Note that the configured `MessageCodesResolver` will automatically generate error code variations which include the object name and the field name.

      参数:
        `descriptor` - the JSR-303 ConstraintDescriptor for the current violation
      返回:
        a corresponding error code (for use with `Errors`)
      从以下版本开始:
        4.2
      另请参阅:
        `ConstraintDescriptor.getAnnotation()`, `MessageCodesResolver`

    - #### getArgumentsForConstraint

          protected Object[] getArgumentsForConstraint(String objectName,
                                                       String field,
                                                       ConstraintDescriptor<?> descriptor)

      Return FieldError arguments for a validation error on the given field. Invoked for each violated constraint.

      The default implementation returns a first argument indicating the field name (see `getResolvableField(java.lang.String, java.lang.String)`). Afterwards, it adds all actual constraint annotation attributes (i.e. excluding "message", "groups" and "payload") in alphabetical order of their attribute names.

      Can be overridden to e.g. add further attributes from the constraint descriptor.

      参数:
        `objectName` - the name of the target object
        `field` - the field that caused the binding error
        `descriptor` - the JSR-303 constraint descriptor
      返回:
        the Object array that represents the FieldError arguments
      另请参阅:
        `DefaultMessageSourceResolvable.getArguments()`, `DefaultMessageSourceResolvable`, `DefaultBindingErrorProcessor.getArgumentsForBindError(java.lang.String, java.lang.String)`

    - #### getResolvableField

          protected MessageSourceResolvable getResolvableField(String objectName,
                                                               String field)

      Build a resolvable wrapper for the specified field, allowing to resolve the field's name in a `MessageSource`.

      The default implementation returns a first argument indicating the field: of type `DefaultMessageSourceResolvable`, with "objectName.field" and "field" as codes, and with the plain field name as default message.

      参数:
        `objectName` - the name of the target object
        `field` - the field that caused the binding error
      返回:
        a corresponding `MessageSourceResolvable` for the specified field
      从以下版本开始:
        4.3

    - #### getRejectedValue

          @Nullable
          protected Object getRejectedValue(String field,
                                                       ConstraintViolation<Object> violation,
                                                       BindingResult bindingResult)

      Extract the rejected value behind the given constraint violation, for exposure through the Spring errors representation.
      参数:
        `field` - the field that caused the binding error
        `violation` - the corresponding JSR-303 ConstraintViolation
        `bindingResult` - a Spring BindingResult for the backing object which contains the current field's value
      返回:
        the invalid value to expose as part of the field error
      从以下版本开始:
        4.2
      另请参阅:
        `ConstraintViolation.getInvalidValue()`, `FieldError.getRejectedValue()`

    - #### validate

          public <T> Set<ConstraintViolation<T>> validate(T object,
                                                          Class<?>... groups)

      指定者:
        `validate` 在接口中 `Validator`

    - #### validateProperty

          public <T> Set<ConstraintViolation<T>> validateProperty(T object,
                                                                  String propertyName,
                                                                  Class<?>... groups)

      指定者:
        `validateProperty` 在接口中 `Validator`

    - #### validateValue

          public <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType,
                                                               String propertyName,
                                                               Object value,
                                                               Class<?>... groups)

      指定者:
        `validateValue` 在接口中 `Validator`

    - #### getConstraintsForClass

          public BeanDescriptor getConstraintsForClass(Class<?> clazz)

      指定者:
        `getConstraintsForClass` 在接口中 `Validator`

    - #### unwrap

          public <T> T unwrap(@Nullable
                              Class<T> type)

      指定者:
        `unwrap` 在接口中 `Validator`

    - #### forExecutables

          public ExecutableValidator forExecutables()

      指定者:
        `forExecutables` 在接口中 `Validator`