首页 > 解决方案 > Grails:如何将 @BindUsing 用于带有 belongsTo 的属性

问题描述

我有一个域对象,其结构如下 -

`

class TaxPlan {

    String taxCode
    String description
    Double taxRate
    Timestamp dateCreated
    Timestamp lastUpdated

    static belongsTo = [location: Location]
}

我想改进“位置”属性以使用 bindUsing 注释。我怎么做?我想要下面的代码 -

class TaxPlan {

    String taxCode
    String description
    Double taxRate
    Timestamp dateCreated
    Timestamp lastUpdated
    @BindUsing({
        obj, source ->

        Location.findByStoreNumber(source['location'])?:RequestContextHolder.currentRequestAttributes()?.session.location

    })
    static belongsTo = [location: Location]
}

标签: grails

解决方案


推荐阅读