(Quick Reference)
bindData
Purpose
Allows fine-grained control of binding request parameters from strings onto objects and the necessary types (data binding).
Examples
// binds request parameters to a target object
bindData(target, params)// exclude firstName and lastName
bindData(target, params, ['firstName', 'lastName'])// only use parameters starting with "author." e.g. author.email
bindData(target, params, "author")
bindData(target, params, ['firstName', 'lastName'], "author")// using inclusive map
bindData(target, params, [include: ['firstName', 'lastName']], "author")// using exclusive map
bindData(target, params, [exclude: ['firstName', 'lastName']], "author")
Description
Usage:
bindData(target, params, excludes, prefix)Arguments:
target - The target object to bind to
params - A Map of source parameters, often the params object when used in a controller
excludes - The parameter names to exclude
prefix - A string representing a prefix to use to filter parameters. A prefix separator of "." is assumed
Note that if an empty List is provided as a value for the include parameter then all fields will be subject to binding if they are not explicitly excluded.
The underlying implementation uses Spring's Data Binding framework. If the target is a domain class, type conversion errors are stored in the
errors property of the domain class.
Refer to the section on
Data Binding in the user guide for more information.