grails - 在Grails GSP中预览多张照片

标签 grails

在我的 Grails应用程序中,我有每个存储在数据库中的字节用户的 2至11张照片,我想为GSP中的用户预览这些图像,我需要知道如何在GSP中预览它们。

我该怎么办?

Controller 中的 Action :

def displayImage() {
    def photo = Photos.findAllByUsers(user)
}

最佳答案

您应该在 Controller 中返回一个图像数组:

def showImages() {
    def photos = Photos.findAllByUsers(user)
    [photos: photos]
}

def displayImage(photo) {
    def image = photo.photo // byte array
    response.setHeader('Content-length', image.length)
    response.contentType = 'image/png' // or the appropriate image content type
    response.outputStream << image
    response.outputStream.flush()
}

并在showImages.gsp文件中将其显示为:
<g:each var="photo" in="${photos}">
     <img src="${createLink(controller: 'myController', action: 'displayImage', params: ['photo': photo])}"/>
</g:each>

关于grails - 在Grails GSP中预览多张照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34984223/

相关文章:

grails - 将 Grails 应用程序转换为插件

oracle - 带有 Oracle 厚 OCI 驱动程序的 Grails 使用错误的用户向 Oracle 进行身份验证

grails - Grails war命令未设置环境

grails - 在 Grails 中捕获 CertificateExpired 异常

loops - Grails-仅在g:each中的前十个值

Grails PayPal 插件响应通知

mongodb - 有没有更快的方法来遍历Grails中的MongoResultList?

grails - 我想从一个gsp获取表单数据,并想在另一个gsp中访问该数据,并希望将该数据插入表中,我该怎么做?

javascript - 如何禁用 h2 标签的 cufon 样式?

grails - 使用Spring Security Rest插件时从GitHub接收弃用警告