Is there a way to utilize bindData
in a service other than using the deprecated BindDynamicMethod
? I can\'t just use
TestObject testOb
If you are using Grails 3.* then the service class can implement DataBinder trait and implement bindData()
as shown below example:
import grails.web.databinding.DataBinder
class SampleService implements DataBinder {
def serviceMethod(params) {
Test test = new Test()
bindData(test, params)
test
}
class Test {
String name
Integer age
}
}
This is how I quickly tried that in grails console:
grailsApplication.mainContext.getBean('sampleService').serviceMethod(name: 'abc', age: 10)