我按照link上的说明推荐我更新我的bootstrap 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')
}
}
答案 0 :(得分:2)
它位于“engagementlevels”包中,但BootStrap.groovy位于默认包中。为该类添加导入:
import grails.converters.JSON
import engagementlevels.UserMapping
class BootStrap {
def init = { servletContext ->
JSON.registerObjectMarshaller(UserMapping) {
def rA = [userId: it.id]
}
}
}