Class ServletRequestDataBinder

All Implemented Interfaces:
PropertyEditorRegistry, TypeConverter
Direct Known Subclasses:
ExtendedServletRequestDataBinder

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 Spring Web MVC and Spring 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. 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();
 ...
Author:
Rod Johnson, Juergen Hoeller
See Also:
  • Constructor Details

    • ServletRequestDataBinder

      public ServletRequestDataBinder(@Nullable Object target)
      Create a new ServletRequestDataBinder instance, with default object name.
      Parameters:
      target - the target object to bind onto (or null if the binder is just used to convert a plain parameter value)
      See Also:
    • ServletRequestDataBinder

      public ServletRequestDataBinder(@Nullable Object target, String objectName)
      Create a new ServletRequestDataBinder instance.
      Parameters:
      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
  • Method Details