【问题标题】:Grails 3.0.9 createLink in my gsp is not working我的 gsp 中的 Grails 3.0.9 createLink 不起作用
【发布时间】:2015-11-26 06:18:01
【问题描述】:

我正在尝试使用以下方法显示存储在我的模型中的图像:

<img src="${createLink(controller:'attachments', action:'showImage', id: attachmentInstance.id)}" />

这是控制器附件中的 showImage 方法:

def showImage= {
println "In showImage"
    def attachmentInstance = Attachment.get(params.id)
    byte[] b = attachmentInstance.image
    response.setContentLength(b.length)
    response.getOutputStream().write(b) 
}

这是我的域类:

class Attachment {
byte[] image
String imageType 
int imageSize
String attachmentType
String fileName

static mapping = {
    image(sqlType: "blob")
    columns {
         '*'(nullable: true)
    }                   
}   

}

该操作没有被执行,我有一个原则来验证它。

图像在文件中,此代码已在以前版本的 Grails 中使用。

是我做错了什么还是有错误?

【问题讨论】:

  • 我很确定控制器方法现在必须是方法,而不是闭包。所以def showImage() { ... } 而不是def showImage = { ... } ...这就是问题所在。

标签: grails


【解决方案1】:

旧版本的 Grails 控制器使用闭包而不是方法。较新的版本在控制器上使用实际方法而不是闭包。所以你的方法应该是:

def showImage() {
...
}

而不是

def showImage = {
...
}

【讨论】:

  • 做到了!谢谢!
  • 没问题。您可能想接受答案,以便其他人知道它也解决了问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-29
  • 2016-02-23
  • 2016-10-15
  • 1970-01-01
  • 2011-03-20
  • 1970-01-01
相关资源
最近更新 更多