Grails 无法设置只读属性:params

Grails 无法设置只读属性:params,grails,params,Grails,Params,我试图保存一张图片并返回它的访问url,但系统抛出了一个关于params的异常:“无法设置只读属性:params” def upload() { def attachmentInstance = new Attachment(utype:params.type, udata:params.data) if (!attachmentInstance.save(flush: true)) { render(view: "create", model: [attachm

我试图保存一张图片并返回它的访问url,但系统抛出了一个关于params的异常:“无法设置只读属性:params”

def upload() {
    def attachmentInstance = new Attachment(utype:params.type, udata:params.data)
    if (!attachmentInstance.save(flush: true)) {
        render(view: "create", model: [attachmentInstance: attachmentInstance])
        return
    }

    def subMap = [url:"${createLink(controller:'attachment', action:'renderImg', params:'[id:${attachmentInstance.id}]')}", width:0, height:0]

    def jsonMap = [id:attachmentInstance.id, type:"image", thumbnail:"", data:subMap]

    def result = [result:jsonMap]

    render result as JSON
}

它看起来有点太复杂了,你能试试吗:

def subMap = [url:createLink(controller:'attachment', action:'renderImg', params:[id:attachmentInstance.id]), width:0, height:0]

我认为您不能像使用
def subMap
行那样嵌套gstring
${createLink…
包含另一个
${}
。我以前遇到过这个问题,我认为您必须将第二个
${}
存储在变量中,然后引用变量(?)。