gpt4 book ai didi

grails - Bootstrap.groovy中的自定义JSON不为域返回此类属性错误

转载 作者:行者123 更新时间:2023-12-02 15:11:34 25 4
gpt4 key购买 nike

我正在按照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')
}
}

最佳答案

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

import grails.converters.JSON
import engagementlevels.UserMapping

class BootStrap {

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

关于grails - Bootstrap.groovy中的自定义JSON不为域返回此类属性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14330978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com