Grails服务中的绑定数据 [英] Grails binddata in service

查看:66
本文介绍了Grails服务中的绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了使用不推荐使用的BindDynamicMethod之外,是否可以在服务中利用bindData?我不能只是使用

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

TestObject testObject = new TestObject()
TestObject testObject.properties = params

TestObject testObject = new TestObject(params)

因为我有一个自定义的绑定方法,该方法使用了TestObject类中的@BindUsing批注.

because I have a custom bind method utilizing the @BindUsing annotation within my TestObject class.

推荐答案

在Grails 2.4.4中,您可以执行以下操作:

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
    }
}

这篇关于Grails服务中的绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆