0

我正在按照此链接上的说明进行操作,该说明建议我更新我的引导 groovy 类。

// Bootstrap.groovy
import grails.converters.JSON

class BootStrap {

    def init = { servletContext ->
        JSON.registerObjectMarshaller(UserMapping) {
            def rA = [:]
            ra['userId'] = it.id
        }
    }
    def destroy = {
    }
}

但它返回错误:

ERROR context.GrailsContextLoader  - Error initializing the application: No such property: UserMapping for class: BootStrap
Message: No such property: UserMapping for class: BootStrap

我的域类看起来像:

# UserMapping.groovy
package engagementlevels

class UserMapping {

    String username
    String email
    Date insertTime
    String type
    String flags

    static belongsTo = [groupMapping: GroupMapping]

    static mapping = {
        // Custom Mappings here
    }

    static hibernateFilters = {
        // Filters here
    }

    transient beforeInsert = {
        throw new RuntimeException('create not allowed')
    }
    transient beforeUpdate = {
        throw new RuntimeException('update not allowed')
    }
    transient beforeDelete = {
        throw new RuntimeException('delete not allowed')
    } 
}
4

1 回答 1

2

它在“engagementlevels”包中,但 BootStrap.groovy 在默认包中。为类添加导入:

import grails.converters.JSON
import engagementlevels.UserMapping

class BootStrap {

   def init = { servletContext ->
       JSON.registerObjectMarshaller(UserMapping) {
          def rA = [userId: it.id]
       }
   }
}
于 2013-01-15T04:09:08.377 回答