org.springframework.validation.DataBinder to perform data binding
from web 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 used for manual data binding in custom web controllers or interceptors
that build on Spring's org.
abstraction: e.g. in a org.
implementation. Simply instantiate a WebRequestDataBinder for each binding
process, and invoke bind with the current WebRequest as argument:
MyBean myBean = new MyBean(); // apply binder to custom target object WebRequestDataBinder binder = new WebRequestDataBinder(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(); ...
bind(org.springframework.web.context.request.WebRequest) , registerCustomEditor, setAllowedFields, setRequiredFields, setFieldMarkerPrefix
| Access | Constructor and Description |
|---|---|
| public | WebRequestDataBinder(Object
the target object to bind onto (or target)null
if the binder is just used to convert a plain parameter value)Create a new WebRequestDataBinder instance, with default object name. |
| public | WebRequestDataBinder(Object
the target object to bind onto (or target, String null
if the binder is just used to convert a plain parameter value)the name of the target object objectName)Create a new WebRequestDataBinder instance. |
| Modifier and Type | Method and Description |
|---|---|
| public void | bind(WebRequest
the request with parameters to bind (can be multipart) request)Bind the parameters of the given request to this binder's target, also binding multipart files in case of a multipart request. |
| public void | |
| public void | construct(WebRequest
the request to bind request)Use a default or single data constructor to create the target by binding request parameters, multipart files, or parts to constructor args. |
| protected boolean | shouldConstructArgument(MethodParameter param)
Overrides org. |
| WebRequestDataBinder | back to summary |
|---|---|
| public WebRequestDataBinder(Object target) Create a new WebRequestDataBinder instance, with default object name.
| |
| WebRequestDataBinder | back to summary |
|---|---|
| public WebRequestDataBinder(Object target, String objectName) Create a new WebRequestDataBinder instance. | |
| bind | back to summary |
|---|---|
| public void bind(WebRequest 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. Servlet Part binding is also supported when the request has not been parsed to MultipartRequest via MultipartResolver.
| |
| closeNoCatch | back to summary |
|---|---|
| public void closeNoCatch() throws BindException 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.
| |
| construct | back to summary |
|---|---|
| public void construct(WebRequest request) Use a default or single data constructor to create the target by binding request parameters, multipart files, or parts to constructor args. After the call, use
| |
| shouldConstructArgument | back to summary |
|---|---|
| protected boolean shouldConstructArgument(MethodParameter param) Overrides org. Doc from org. Whether to instantiate the constructor argument of the given type, matching its own constructor arguments to bind values. By default, simple value types, maps, collections, and arrays are excluded from nested constructor binding initialization.
| |