grails无法在列表视图中显示图像

grails无法在列表视图中显示图像,grails,Grails,我想在grails项目的列表视图中显示一个图像 我在控制器中编写了一个操作,用于在列表中显示它 def showImage () { def testUnitInstance = TestUnit.get(params.testUnitId) response.setContentType("image/jpeg") response.setContentLength(testUnitInstance.image.size()) response.outputSt

我想在grails项目的列表视图中显示一个图像

我在控制器中编写了一个操作,用于在列表中显示它

def showImage () {
    def testUnitInstance = TestUnit.get(params.testUnitId)
    response.setContentType("image/jpeg")
    response.setContentLength(testUnitInstance.image.size())
    response.outputStream << testUnitInstance.image
    response.outputStream.flush()
    }
def showImage(){
def testUnitInstance=TestUnit.get(params.testUnitId)
response.setContentType(“图像/jpeg”)
response.setContentLength(testUnitInstance.image.size())

response.outputStream您是否检查了您的操作是否被正确调用?我可以建议您在那里使用
${}
语法。例如
src=“${createLink(controller:'testUnit'…)}”
@aiolos我通过在showImage操作中打印hi进行了检查确定,完整示例
src=“${createLink(controller:'testUnit',action:'showImage',params:[testUnitId:testUnitInstance.id])“
如果您的html是正确的,并且控制台上打印了“hi”,那么您的响应中有一个错误。请在showImage()中调试代码
<img src="<g:createLink controller='testUnit' action='showImage' 
                    params='[testUnitId:testUnitInstance.id]'/>" height="14px" width="14px" alt="img"
                                    style="padding-left: 20px;"/>