类 ValidationUtils
- java.lang.Object
- org.springframework.validation.ValidationUtils
public abstract class ValidationUtils extends Object
Utility class offering convenient methods for invoking aValidatorand for rejecting empty fields.Checks for an empty field in
Validatorimplementations can become one-liners when usingrejectIfEmpty(org.springframework.validation.Errors, java.lang.String, java.lang.String)orrejectIfEmptyOrWhitespace(org.springframework.validation.Errors, java.lang.String, java.lang.String).
构造器概要
构造器 构造器 说明 ValidationUtils()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static voidinvokeValidator(Validator validator, Object target, Errors errors)static voidinvokeValidator(Validator validator, Object target, Errors errors, Object... validationHints)static voidrejectIfEmpty(Errors errors, String field, String errorCode)Reject the given field with the given error code if the value is empty.static voidrejectIfEmpty(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 voidrejectIfEmpty(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 voidrejectIfEmpty(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 voidrejectIfEmptyOrWhitespace(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 voidrejectIfEmptyOrWhitespace(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 voidrejectIfEmptyOrWhitespace(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 voidrejectIfEmptyOrWhitespace(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.
构造器详细资料
ValidationUtils
public ValidationUtils()
方法详细资料
invokeValidator
public static void invokeValidator(Validator validator, Object target, Errors errors)
- 参数:
validator- theValidatorto be invokedtarget- the object to bind the parameters toerrors- theErrorsinstance that should store the errors- 抛出:
IllegalArgumentException- if either of theValidatororErrorsarguments isnull, or if the suppliedValidatordoes notsupportthe validation of the supplied object's type
invokeValidator
public static void invokeValidator(Validator validator, Object target, Errors errors, @Nullable Object... validationHints)
- 参数:
validator- theValidatorto be invokedtarget- the object to bind the parameters toerrors- theErrorsinstance that should store the errorsvalidationHints- one or more hint objects to be passed to the validation engine- 抛出:
IllegalArgumentException- if either of theValidatororErrorsarguments isnull, or if the suppliedValidatordoes notsupportthe 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
nullor the empty string "".The object whose field is being validated does not need to be passed in because the
Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- 参数:
errors- theErrorsinstance to register errors onfield- the field name to checkerrorCode- 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
nullor the empty string "".The object whose field is being validated does not need to be passed in because the
Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- 参数:
errors- theErrorsinstance to register errors onfield- the field name to checkerrorCode- error code, interpretable as message keydefaultMessage- 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
nullor the empty string "".The object whose field is being validated does not need to be passed in because the
Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- 参数:
errors- theErrorsinstance to register errors onfield- the field name to checkerrorCode- the error code, interpretable as message keyerrorArgs- the error arguments, for argument binding via MessageFormat (can benull)
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
nullor the empty string "".The object whose field is being validated does not need to be passed in because the
Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- 参数:
errors- theErrorsinstance to register errors onfield- the field name to checkerrorCode- the error code, interpretable as message keyerrorArgs- the error arguments, for argument binding via MessageFormat (can benull)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
Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- 参数:
errors- theErrorsinstance to register errors onfield- the field name to checkerrorCode- 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
Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- 参数:
errors- theErrorsinstance to register errors onfield- the field name to checkerrorCode- the error code, interpretable as message keydefaultMessage- 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
Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- 参数:
errors- theErrorsinstance to register errors onfield- the field name to checkerrorCode- the error code, interpretable as message keyerrorArgs- the error arguments, for argument binding via MessageFormat (can benull)
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
Errorsinstance can resolve field values by itself (it will usually hold an internal reference to the target object).- 参数:
errors- theErrorsinstance to register errors onfield- the field name to checkerrorCode- the error code, interpretable as message keyerrorArgs- the error arguments, for argument binding via MessageFormat (can benull)defaultMessage- fallback default message