我的gsp中的Grails 3.0.9 createLink不工作

我的gsp中的Grails 3.0.9 createLink不工作,grails,Grails,我尝试使用以下方式显示存储在模型中的图像: 以下是控制器附件中的showImage方法: def showImage= { println "In showImage" def attachmentInstance = Attachment.get(params.id) byte[] b = attachmentInstance.image response.setContentLength(b.length) response.getOutputStream(

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

以下是控制器附件中的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中使用


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

旧版本的Grails控制器使用闭包而不是方法。较新版本在控制器上使用实际方法,而不是闭包。因此,您的方法应该是:

def showImage() {
...
}
而不是

def showImage = {
...
}

我非常确定控制器方法现在必须是方法,而不是闭包。因此,
def showImage(){…}
而不是
def showImage={…}
。。。这就是问题所在,就是这样!谢谢没问题。你可能想接受这个答案,让别人知道它也解决了问题。