如何在grails GSP中显示图像? [英] How to display image in grails GSP?
本文介绍了如何在grails GSP中显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是2个域的类:
class Photo {
byte [] file
static belongsTo = Profile
}
class档案{
字符串全名
设置照片
static hasMany = [照片:照片]
}
相关控制器代码片段:
class PhotoController {
def viewImage = {
def photo = Photo.get(params.id)
byte [] image = photo.file
response.outputStream<<图片
}
}
片段:
< img class =Photosrc =$ {createLink(controller:'photo' ,action:'viewImage',id:'profileInstance.photos.get(1).id')}/>
现在我该如何访问照片,以便它能显示在GSP上?我很确定
profileInstance.photos.get(1).id
是不正确的。
code> profileInstance.photos.toArray()[0] .id
或
profileInstance.photos.iterator()。next()
I'm still learning Grails and seem to have hit a stumbling block.
Here are the 2 domain classes:
class Photo {
byte[] file
static belongsTo = Profile
}
class Profile {
String fullName
Set photos
static hasMany = [photos:Photo]
}
The relevant controller snippet:
class PhotoController {
def viewImage = {
def photo = Photo.get( params.id )
byte[] image = photo.file
response.outputStream << image
}
}
Finally the GSP snippet:
<img class="Photo" src="${createLink(controller:'photo', action:'viewImage', id:'profileInstance.photos.get(1).id')}" />
Now how do I access the photo so that it will be shown on the GSP? I'm pretty sure that
profileInstance.photos.get(1).id
is not correct.
解决方案
As it is a Set, if you want the first element, you will have to go:
profileInstance.photos.toArray()[0].id
or
profileInstance.photos.iterator().next()
这篇关于如何在grails GSP中显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文