类 ServletRequestDataBinder

java.lang.Object
cn.taketoday.validation.DataBinder
cn.taketoday.web.bind.WebDataBinder
cn.taketoday.web.bind.ServletRequestDataBinder
所有已实现的接口:
cn.taketoday.beans.PropertyEditorRegistry, cn.taketoday.beans.TypeConverter

public class ServletRequestDataBinder extends WebDataBinder
Special DataBinder to perform data binding from servlet request parameters to JavaBeans, including support for multipart files.

WARNING: Data binding can lead to security issues by exposing parts of the object graph that are not meant to be accessed or modified by external clients. Therefore the design and use of data binding should be considered carefully with regard to security. For more details, please refer to the dedicated sections on data binding for Infra Web MVC and Infra WebFlux in the reference manual.

See the DataBinder/WebDataBinder superclasses for customization options, which include specifying allowed/required fields, and registering custom property editors.

Can also be used for manual data binding in custom web controllers: for example, in a plain Controller implementation or in a MultiActionController handler method. Simply instantiate a ServletRequestDataBinder for each binding process, and invoke bind with the current ServletRequest as argument:

 MyBean myBean = new MyBean();
 // apply binder to custom target object
 ServletRequestDataBinder binder = new ServletRequestDataBinder(myBean);
 // register custom editors, if desired
 binder.registerCustomEditor(...);
 // trigger actual binding of request parameters
 binder.bind(request);
 // optionally evaluate binding errors
 Errors errors = binder.getErrors();
 ...
从以下版本开始:
4.0 2022/3/2 16:30
作者:
Rod Johnson, Juergen Hoeller, Harry Yang
另请参阅:
  • 嵌套类概要

    从类继承的嵌套类/接口 cn.taketoday.web.bind.WebDataBinder

    WebDataBinder.RequestValueResolver

    从类继承的嵌套类/接口 cn.taketoday.validation.DataBinder

    cn.taketoday.validation.DataBinder.NameResolver, cn.taketoday.validation.DataBinder.ValueResolver
  • 字段概要

    从类继承的字段 cn.taketoday.web.bind.WebDataBinder

    DEFAULT_FIELD_DEFAULT_PREFIX, DEFAULT_FIELD_MARKER_PREFIX

    从类继承的字段 cn.taketoday.validation.DataBinder

    DEFAULT_AUTO_GROW_COLLECTION_LIMIT, DEFAULT_OBJECT_NAME, logger
  • 构造器概要

    构造器
    构造器
    说明
    Create a new ServletRequestDataBinder instance, with default object name.
    ServletRequestDataBinder(Object target, String objectName)
    Create a new ServletRequestDataBinder instance.
  • 方法概要

    修饰符和类型
    方法
    说明
    protected void
    addBindValues(cn.taketoday.beans.PropertyValues mpvs, ServletRequest request)
    Extension point that subclasses can use to add extra bind values for a request.
    void
    Bind the parameters of the given request to this binder's target, also binding multipart files in case of a multipart request.
    void
    Treats errors as fatal.

    从类继承的方法 cn.taketoday.validation.DataBinder

    addCustomFormatter, addCustomFormatter, addCustomFormatter, addValidators, applyPropertyValues, bind, checkAllowedFields, checkRequiredFields, close, construct, convertIfNecessary, convertIfNecessary, convertIfNecessary, convertIfNecessary, createBeanPropertyBindingResult, createDirectFieldBindingResult, findCustomEditor, getAllowedFields, getAutoGrowCollectionLimit, getBindingErrorProcessor, getBindingResult, getConversionService, getDisallowedFields, getInternalBindingResult, getNameResolver, getObjectName, getPropertyAccessor, getPropertyEditorRegistry, getRequiredFields, getSimpleTypeConverter, getTarget, getTargetType, getTypeConverter, getValidator, getValidators, getValidatorsToApply, initBeanPropertyAccess, initDirectFieldAccess, isAllowed, isAutoGrowNestedPaths, isDeclarativeBinding, isIgnoreInvalidFields, isIgnoreUnknownFields, registerCustomEditor, registerCustomEditor, replaceValidators, setAllowedFields, setAutoGrowCollectionLimit, setAutoGrowNestedPaths, setBindingErrorProcessor, setConversionService, setDeclarativeBinding, setDisallowedFields, setExcludedValidators, setIgnoreInvalidFields, setIgnoreUnknownFields, setMessageCodesResolver, setNameResolver, setRequiredFields, setTargetType, setValidator, shouldNotBindPropertyValues, validate, validate

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

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • ServletRequestDataBinder

      public ServletRequestDataBinder(@Nullable Object target)
      Create a new ServletRequestDataBinder instance, with default object name.
      参数:
      target - the target object to bind onto (or null if the binder is just used to convert a plain parameter value)
      另请参阅:
      • DataBinder.DEFAULT_OBJECT_NAME
    • ServletRequestDataBinder

      public ServletRequestDataBinder(@Nullable Object target, String objectName)
      Create a new ServletRequestDataBinder instance.
      参数:
      target - the target object to bind onto (or null if the binder is just used to convert a plain parameter value)
      objectName - the name of the target object
  • 方法详细资料

    • bind

      public void bind(ServletRequest request)
      Bind the parameters of the given request to this binder's target, also binding multipart files in case of a multipart request.

      This call can create field errors, representing basic binding errors like a required field (code "required"), or type mismatch between value and bean property (code "typeMismatch").

      Multipart files are bound via their parameter name, just like normal HTTP parameters: i.e. "uploadedFile" to an "uploadedFile" bean property, invoking a "setUploadedFile" setter method.

      The type of the target property for a multipart file can be MultipartFile, byte[], or String. The latter two receive the contents of the uploaded file; all metadata like original file name, content type, etc are lost in those cases.

      参数:
      request - the request with parameters to bind (can be multipart)
      另请参阅:
      • MultipartFile
      • DataBinder.bind(cn.taketoday.beans.PropertyValues)
    • addBindValues

      protected void addBindValues(cn.taketoday.beans.PropertyValues mpvs, ServletRequest request)
      Extension point that subclasses can use to add extra bind values for a request. Invoked before WebDataBinder.doBind(PropertyValues). The default implementation is empty.
      参数:
      mpvs - the property values that will be used for data binding
      request - the current request
    • closeNoCatch

      public void closeNoCatch() throws RequestBindingException
      Treats errors as fatal.

      Use this method only if it's an error if the input isn't valid. This might be appropriate if all input is from dropdowns, for example.

      覆盖:
      closeNoCatch 在类中 WebDataBinder
      抛出:
      RequestBindingException - subclass of ServletException on any binding problem