【发布时间】: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