org.springframework.validation

## 类 ValidationUtils

- java.lang.Object
- - org.springframework.validation.ValidationUtils

-     public abstract class ValidationUtils
      extends Object

  Utility class offering convenient methods for invoking a `Validator` and for rejecting empty fields.

  Checks for an empty field in `Validator` implementations can become one-liners when using `rejectIfEmpty(org.springframework.validation.Errors, java.lang.String, java.lang.String)` or `rejectIfEmptyOrWhitespace(org.springframework.validation.Errors, java.lang.String, java.lang.String)`.

  从以下版本开始:
    06.05.2003
  作者:
    Juergen Hoeller, Dmitriy Kopylenko
  另请参阅:
    `Validator`, `Errors`

- - ### 构造器概要

    构造器
    构造器和说明
    `ValidationUtils()`

  - ### 方法概要

    所有方法 静态方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `static void` | `invokeValidator(Validator validator, Object obj, Errors errors)` Invoke the given `Validator` for the supplied object and `Errors` instance.
    `static void` | `invokeValidator(Validator validator, Object obj, Errors errors, Object... validationHints)` Invoke the given `Validator`/`SmartValidator` for the supplied object and `Errors` instance.
    `static void` | `rejectIfEmpty(Errors errors, String field, String errorCode)` Reject the given field with the given error code if the value is empty.
    `static void` | `rejectIfEmpty(Errors errors, String field, String errorCode, Object[] errorArgs)` Reject the given field with the given error code and error arguments if the value is empty.
    `static void` | `rejectIfEmpty(Errors errors, String field, String errorCode, Object[] errorArgs, String defaultMessage)` Reject the given field with the given error code, error arguments and default message if the value is empty.
    `static void` | `rejectIfEmpty(Errors errors, String field, String errorCode, String defaultMessage)` Reject the given field with the given error code and default message if the value is empty.
    `static void` | `rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode)` Reject the given field with the given error code if the value is empty or just contains whitespace.
    `static void` | `rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, Object[] errorArgs)` Reject the given field with the given error code and error arguments if the value is empty or just contains whitespace.
    `static void` | `rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, Object[] errorArgs, String defaultMessage)` Reject the given field with the given error code, error arguments and default message if the value is empty or just contains whitespace.
    `static void` | `rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode, String defaultMessage)` Reject the given field with the given error code and default message if the value is empty or just contains whitespace.

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

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

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

    - #### ValidationUtils

          public ValidationUtils()

  - ### 方法详细资料

    - #### invokeValidator

          public static void invokeValidator(Validator validator,
                                             Object obj,
                                             Errors errors)

      Invoke the given `Validator` for the supplied object and `Errors` instance.
      参数:
        `validator` - the `Validator` to be invoked (must not be `null`)
        `obj` - the object to bind the parameters to
        `errors` - the `Errors` instance that should store the errors (must not be `null`)
      抛出:
        `IllegalArgumentException` - if either of the `Validator` or `Errors` arguments is `null`, or if the supplied `Validator` does not `support` the validation of the supplied object's type

    - #### invokeValidator

          public static void invokeValidator(Validator validator,
                                             @Nullable
                                             Object obj,
                                             Errors errors,
                                             @Nullable
                                             Object... validationHints)

      Invoke the given `Validator`/`SmartValidator` for the supplied object and `Errors` instance.
      参数:
        `validator` - the `Validator` to be invoked (must not be `null`)
        `obj` - the object to bind the parameters to
        `errors` - the `Errors` instance that should store the errors (must not be `null`)
        `validationHints` - one or more hint objects to be passed to the validation engine
      抛出:
        `IllegalArgumentException` - if either of the `Validator` or `Errors` arguments is `null`, or if the supplied `Validator` does not `support` the validation of the supplied object's type

    - #### rejectIfEmpty

          public static void rejectIfEmpty(Errors errors,
                                           String field,
                                           String errorCode)

      Reject the given field with the given error code if the value is empty.

      An 'empty' value in this context means either `null` or the empty string "".

      The object whose field is being validated does not need to be passed in because the `Errors` instance can resolve field values by itself (it will usually hold an internal reference to the target object).

      参数:
        `errors` - the `Errors` instance to register errors on
        `field` - the field name to check
        `errorCode` - the error code, interpretable as message key

    - #### rejectIfEmpty

          public static void rejectIfEmpty(Errors errors,
                                           String field,
                                           String errorCode,
                                           String defaultMessage)

      Reject the given field with the given error code and default message if the value is empty.

      An 'empty' value in this context means either `null` or the empty string "".

      The object whose field is being validated does not need to be passed in because the `Errors` instance can resolve field values by itself (it will usually hold an internal reference to the target object).

      参数:
        `errors` - the `Errors` instance to register errors on
        `field` - the field name to check
        `errorCode` - error code, interpretable as message key
        `defaultMessage` - fallback default message

    - #### rejectIfEmpty

          public static void rejectIfEmpty(Errors errors,
                                           String field,
                                           String errorCode,
                                           Object[] errorArgs)

      Reject the given field with the given error code and error arguments if the value is empty.

      An 'empty' value in this context means either `null` or the empty string "".

      The object whose field is being validated does not need to be passed in because the `Errors` instance can resolve field values by itself (it will usually hold an internal reference to the target object).

      参数:
        `errors` - the `Errors` instance to register errors on
        `field` - the field name to check
        `errorCode` - the error code, interpretable as message key
        `errorArgs` - the error arguments, for argument binding via MessageFormat (can be `null`)

    - #### rejectIfEmpty

          public static void rejectIfEmpty(Errors errors,
                                           String field,
                                           String errorCode,
                                           @Nullable
                                           Object[] errorArgs,
                                           @Nullable
                                           String defaultMessage)

      Reject the given field with the given error code, error arguments and default message if the value is empty.

      An 'empty' value in this context means either `null` or the empty string "".

      The object whose field is being validated does not need to be passed in because the `Errors` instance can resolve field values by itself (it will usually hold an internal reference to the target object).

      参数:
        `errors` - the `Errors` instance to register errors on
        `field` - the field name to check
        `errorCode` - the error code, interpretable as message key
        `errorArgs` - the error arguments, for argument binding via MessageFormat (can be `null`)
        `defaultMessage` - fallback default message

    - #### rejectIfEmptyOrWhitespace

          public static void rejectIfEmptyOrWhitespace(Errors errors,
                                                       String field,
                                                       String errorCode)

      Reject the given field with the given error code if the value is empty or just contains whitespace.

      An 'empty' value in this context means either `null`, the empty string "", or consisting wholly of whitespace.

      The object whose field is being validated does not need to be passed in because the `Errors` instance can resolve field values by itself (it will usually hold an internal reference to the target object).

      参数:
        `errors` - the `Errors` instance to register errors on
        `field` - the field name to check
        `errorCode` - the error code, interpretable as message key

    - #### rejectIfEmptyOrWhitespace

          public static void rejectIfEmptyOrWhitespace(Errors errors,
                                                       String field,
                                                       String errorCode,
                                                       String defaultMessage)

      Reject the given field with the given error code and default message if the value is empty or just contains whitespace.

      An 'empty' value in this context means either `null`, the empty string "", or consisting wholly of whitespace.

      The object whose field is being validated does not need to be passed in because the `Errors` instance can resolve field values by itself (it will usually hold an internal reference to the target object).

      参数:
        `errors` - the `Errors` instance to register errors on
        `field` - the field name to check
        `errorCode` - the error code, interpretable as message key
        `defaultMessage` - fallback default message

    - #### rejectIfEmptyOrWhitespace

          public static void rejectIfEmptyOrWhitespace(Errors errors,
                                                       String field,
                                                       String errorCode,
                                                       @Nullable
                                                       Object[] errorArgs)

      Reject the given field with the given error code and error arguments if the value is empty or just contains whitespace.

      An 'empty' value in this context means either `null`, the empty string "", or consisting wholly of whitespace.

      The object whose field is being validated does not need to be passed in because the `Errors` instance can resolve field values by itself (it will usually hold an internal reference to the target object).

      参数:
        `errors` - the `Errors` instance to register errors on
        `field` - the field name to check
        `errorCode` - the error code, interpretable as message key
        `errorArgs` - the error arguments, for argument binding via MessageFormat (can be `null`)

    - #### rejectIfEmptyOrWhitespace

          public static void rejectIfEmptyOrWhitespace(Errors errors,
                                                       String field,
                                                       String errorCode,
                                                       @Nullable
                                                       Object[] errorArgs,
                                                       @Nullable
                                                       String defaultMessage)

      Reject the given field with the given error code, error arguments and default message if the value is empty or just contains whitespace.

      An 'empty' value in this context means either `null`, the empty string "", or consisting wholly of whitespace.

      The object whose field is being validated does not need to be passed in because the `Errors` instance can resolve field values by itself (it will usually hold an internal reference to the target object).

      参数:
        `errors` - the `Errors` instance to register errors on
        `field` - the field name to check
        `errorCode` - the error code, interpretable as message key
        `errorArgs` - the error arguments, for argument binding via MessageFormat (can be `null`)
        `defaultMessage` - fallback default message