Grails binddata in service

后端 未结 3 1753
清歌不尽
清歌不尽 2021-02-04 20:20

Is there a way to utilize bindData in a service other than using the deprecated BindDynamicMethod? I can\'t just use

TestObject testOb         


        
3条回答
  •  深忆病人
    2021-02-04 20:30

    In Grails 2.4.4 you can do something like this:

    // grails-app/services/demo/HelperService.groovy
    package demo
    
    import org.grails.databinding.SimpleMapDataBindingSource
    
    class HelperService {
    
        def grailsWebDataBinder
    
        TestObject getNewTestObject(Map args) {
            def obj = new TestObject()
            grailsWebDataBinder.bind obj, args as SimpleMapDataBindingSource
            obj
        }
    }
    

提交回复
热议问题