接口 BindingResult
- 所有超级接口:
Errors
- 所有已知实现类:
AbstractBindingResult
,AbstractPropertyBindingResult
,BeanPropertyBindingResult
,BindException
,DirectFieldBindingResult
,MapBindingResult
,WebExchangeBindException
public interface BindingResult extends Errors
General interface that represents binding results. Extends theinterface
for error registration capabilities, allowing for aValidator
to be applied, and adds binding-specific analysis and model building.Serves as result holder for a
DataBinder
, obtained via theDataBinder.getBindingResult()
method. BindingResult implementations can also be used directly, for example to invoke aValidator
on it (e.g. as part of a unit test).- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller
- 另请参阅:
DataBinder
,Errors
,Validator
,BeanPropertyBindingResult
,DirectFieldBindingResult
,MapBindingResult
字段概要
字段 修饰符和类型 字段 说明 static String
MODEL_KEY_PREFIX
Prefix for the name of the BindingResult instance in a model, followed by the object name.从接口继承的字段 org.springframework.validation.Errors
NESTED_PATH_SEPARATOR
方法概要
所有方法 实例方法 抽象方法 默认方法 修饰符和类型 方法 说明 void
addError(ObjectError error)
Add a customObjectError
orFieldError
to the errors list.PropertyEditor
findEditor(String field, Class<?> valueType)
Find a custom property editor for the given type and property.Map<String,Object>
getModel()
Return a model Map for the obtained state, exposing a BindingResult instance as 'MODEL_KEY_PREFIX
+ objectName' and the object itself as 'objectName'.PropertyEditorRegistry
getPropertyEditorRegistry()
Return the underlying PropertyEditorRegistry.Object
getRawFieldValue(String field)
Extract the raw field value for the given field.default String[]
getSuppressedFields()
Return the list of fields that were suppressed during the bind process.Object
getTarget()
Return the wrapped target object, which may be a bean, an object with public fields, a Map - depending on the concrete binding strategy.default void
recordFieldValue(String field, Class<?> type, Object value)
Record the given value for the specified field.default void
recordSuppressedField(String field)
Mark the specified disallowed field as suppressed.String[]
resolveMessageCodes(String errorCode)
Resolve the given error code into message codes.String[]
resolveMessageCodes(String errorCode, String field)
Resolve the given error code into message codes for the given field.从接口继承的方法 org.springframework.validation.Errors
addAllErrors, getAllErrors, getErrorCount, getFieldError, getFieldError, getFieldErrorCount, getFieldErrorCount, getFieldErrors, getFieldErrors, getFieldType, getFieldValue, getGlobalError, getGlobalErrorCount, getGlobalErrors, getNestedPath, getObjectName, hasErrors, hasFieldErrors, hasFieldErrors, hasGlobalErrors, popNestedPath, pushNestedPath, reject, reject, reject, rejectValue, rejectValue, rejectValue, setNestedPath
字段详细资料
MODEL_KEY_PREFIX
static final String MODEL_KEY_PREFIX
Prefix for the name of the BindingResult instance in a model, followed by the object name.
方法详细资料
getTarget
@Nullable Object getTarget()
Return the wrapped target object, which may be a bean, an object with public fields, a Map - depending on the concrete binding strategy.
getModel
Map<String,Object> getModel()
Return a model Map for the obtained state, exposing a BindingResult instance as 'MODEL_KEY_PREFIX
+ objectName' and the object itself as 'objectName'.Note that the Map is constructed every time you're calling this method. Adding things to the map and then re-calling this method will not work.
The attributes in the model Map returned by this method are usually included in the
ModelAndView
for a form view that uses Spring'sbind
tag in a JSP, which needs access to the BindingResult instance. Spring's pre-built form controllers will do this for you when rendering a form view. When building the ModelAndView instance yourself, you need to include the attributes from the model Map returned by this method.
getRawFieldValue
@Nullable Object getRawFieldValue(String field)
Extract the raw field value for the given field. Typically used for comparison purposes.- 参数:
field
- the field to check- 返回:
- the current value of the field in its raw form, or
null
if not known
findEditor
@Nullable PropertyEditor findEditor(@Nullable String field, @Nullable Class<?> valueType)
Find a custom property editor for the given type and property.- 参数:
field
- the path of the property (name or nested path), ornull
if looking for an editor for all properties of the given typevalueType
- the type of the property (can benull
if a property is given but should be specified in any case for consistency checking)- 返回:
- the registered editor, or
null
if none
getPropertyEditorRegistry
@Nullable PropertyEditorRegistry getPropertyEditorRegistry()
Return the underlying PropertyEditorRegistry.- 返回:
- the PropertyEditorRegistry, or
null
if none available for this BindingResult
resolveMessageCodes
String[] resolveMessageCodes(String errorCode)
Resolve the given error code into message codes.Calls the configured
MessageCodesResolver
with appropriate parameters.- 参数:
errorCode
- the error code to resolve into message codes- 返回:
- the resolved message codes
resolveMessageCodes
String[] resolveMessageCodes(String errorCode, String field)
Resolve the given error code into message codes for the given field.Calls the configured
MessageCodesResolver
with appropriate parameters.- 参数:
errorCode
- the error code to resolve into message codesfield
- the field to resolve message codes for- 返回:
- the resolved message codes
addError
void addError(ObjectError error)
Add a customObjectError
orFieldError
to the errors list.Intended to be used by cooperating strategies such as
BindingErrorProcessor
.
recordFieldValue
default void recordFieldValue(String field, Class<?> type, @Nullable Object value)
Record the given value for the specified field.To be used when a target object cannot be constructed, making the original field values available through
Errors.getFieldValue(java.lang.String)
. In case of a registered error, the rejected value will be exposed for each affected field.- 参数:
field
- the field to record the value fortype
- the type of the fieldvalue
- the original value- 从以下版本开始:
- 5.0.4
recordSuppressedField
default void recordSuppressedField(String field)
Mark the specified disallowed field as suppressed.The data binder invokes this for each field value that was detected to target a disallowed field.
getSuppressedFields
default String[] getSuppressedFields()
Return the list of fields that were suppressed during the bind process.Can be used to determine whether any field values were targeting disallowed fields.