Grails 如何将SQL DB中保存的字节数组绑定到DataGrid中GSP中的图像标记?

Grails 如何将SQL DB中保存的字节数组绑定到DataGrid中GSP中的图像标记?,grails,groovy,datagrid,gsp,Grails,Groovy,Datagrid,Gsp,我有类型为Byte[]的域属性 byte[] photos byte[] video 在GSP页面上,我能够成功地在SQL DB中上传我的文件。 当我查看页面以查看行中的元素列表时,我的控制器操作完成了这项工作,我如何将图像源设置为从DB检索到的这个字节数组 我希望我的问题是清楚的 按照说明做了之后,下面是我所做的 def displayGraph() { //def img = params.id // byte array def classified = Classifi

我有类型为Byte[]的域属性

byte[] photos
byte[] video
在GSP页面上,我能够成功地在SQL DB中上传我的文件。 当我查看页面以查看行中的元素列表时,我的控制器操作完成了这项工作,我如何将图像源设置为从DB检索到的这个字节数组

我希望我的问题是清楚的

按照说明做了之后,下面是我所做的

def displayGraph() {
    //def img = params.id // byte array
    def classified = Classified.findById(params.id)
    byte[] imageInByte=classified.photos.toByteArray();

    response.setHeader('Content-length', imageInByte.length)
    response.contentType = 'image/png' // or the appropriate image content type
    response.outputStream << imageInByte
    response.outputStream.flush()

    }

谢谢大家的帮助。我终于解决了这个难题。 以下是通过问题修复的代码:

class ImageProcessingController {

def DisplayImage() {
    def classified = Classified.findById(params.id)
    byte[] imageInByte=classified.photos
    response.contentType = 'image/png' // or the appropriate image content type
    response.outputStream << imageInByte
    response.outputStream.flush()
    }
}

二,。无需使用“toByteArray()”将字节数组转换为字节数组。

这应该会有所帮助,因为它解决了您的问题。如果没有,请更详细地描述您采取了哪些步骤以及哪些步骤不起作用。
2014-05-03 19:17:05,723 [http-bio-8080-exec-3] ERROR errors.GrailsExceptionResolver  -
MissingMethodException occurred when processing request:   
[GET]/XXXClassified/classified/displayGraph/1
No signature of method: [B.toByteArray() is applicable for argument types: () values:  
[]. Stacktrace follows: Message: No signature of method: [B.toByteArray() is applicable  
for argument types: () values: []
class ImageProcessingController {

def DisplayImage() {
    def classified = Classified.findById(params.id)
    byte[] imageInByte=classified.photos
    response.contentType = 'image/png' // or the appropriate image content type
    response.outputStream << imageInByte
    response.outputStream.flush()
    }
}
<td><img height=100, width=100 src="${createLink(controller: 'ImageProcessing', action: 'DisplayImage', params: ['id': classifiedInstance.id])}"/></td>
response.setHeader('Content-length', imageInByte.length)