Grails:具有多列的数据绑定自定义hibernate类型

Grails:具有多列的数据绑定自定义hibernate类型,hibernate,grails,data-binding,groovy,custom-type,Hibernate,Grails,Data Binding,Groovy,Custom Type,我在Grails()中使用自定义hibernate类型,并将该类型映射到多个列。然而,我在弄清楚如何在这些自定义类型上进行数据绑定方面有点困难。我可以使用@BindUsing注释,但是,我只有一个属性和多个列 例如,这里有一个groovy类(它将有一个使用正确定义的CustomDataUserType类创建的自定义类型): 这是一个域模型,它将这个类作为属性 class DomainModel { static mapping = { customData type: C

我在Grails()中使用自定义hibernate类型,并将该类型映射到多个列。然而,我在弄清楚如何在这些自定义类型上进行数据绑定方面有点困难。我可以使用@BindUsing注释,但是,我只有一个属性和多个列

例如,这里有一个groovy类(它将有一个使用正确定义的CustomDataUserType类创建的自定义类型):

这是一个域模型,它将这个类作为属性

class DomainModel
{
  static mapping = {      
    customData type: CustomDataUserType, {
        column name: "field1"
        column name: "field2"
    }

  @BindUsing { obj, source ->
    // The source contains a field/property called customData (otherwise
    //   this BindUsing closure doesn't get called) however, I need two
    //   values
  }
  CustomData customData
}

我的问题是,在BindUsing闭包中,源包含一个值,一个名为customData的属性。但是,我需要两个值来重新创建自定义对象。这个问题通常是如何解决的?

BindUsing闭包被传递给当前对象和一个映射,该映射在代码示例中是源。如果在映射中传递了字段1和字段2,则可以轻松地将它们放入CustomData类型中

例如,将此JSON发布到需要
DomainModel

{
  field1: 'test',
  field2: '1'
}
 @BindUsing { obj, source ->
    CustomData customData = new CustomData(field1: source['field1'],field2: source['field2'])
    return customData
  }
  CustomData customData
域模型中使用以下@BindUsing

{
  field1: 'test',
  field2: '1'
}
 @BindUsing { obj, source ->
    CustomData customData = new CustomData(field1: source['field1'],field2: source['field2'])
    return customData
  }
  CustomData customData
这将通过数据绑定正确创建自定义对象