2012-08-09 302 views
0

我試圖保存圖片,並返回它的訪問的URL,但系統拋出約PARAMS異常:「無法設置只讀屬性: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 
} 
+0

我不認爲你可以嵌套你的GStrings,因爲你有'def subMap'行。 '$ {createLink ...'包含另一個'$ {}''。過去我遇到過這個問題,我想你必須將第二個'$ {}'存儲在變量中,然後引用變量(?)。 – nickdos 2012-08-09 04:03:06

回答

1

它看起來你可以嘗試:

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

謝謝,問題解決了 – MiguAlien 2012-08-09 05:08:25