我有一个JDO类和辅助类图像以存储一个字节数组内的图像GSP,从数组字节图像
JDO类:
@PersistenceCapable
class Recipe{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long key
@Persistent
private String description
@Persistent(serialized = "true")
private Image image;
}
Image类:
class Image implements Serializable {
private byte[] content
private String filename
private String mimeType
}
在gsp页面中,我遍历食谱并想要显示图像。 我可以像这样做一个控制器来获取图像的src。
def viewImage= {
//retrieve photo code here
response.setHeader("Content-disposition", "attachment; filename=${photo.name}")
response.contentType = photo.fileType //'image/jpeg' will do too
response.outputStream << photo.file //'myphoto.jpg' will do too
response.outputStream.flush()
return;
}
但是,这种方式,我必须将配方的密钥发送到此控制器,并再次从数据存储区加载图像。 (我已经实际加载了它,但我认为我无法将这些数据发送到控制器,我可以吗?) 是否没有更方便的方法在gsp页面中显示字节数组中的图像?
看起来像重复http://stackoverflow.com/questions/4502278/grails-displaying-created-image-in-gsp/4502403给我。我的答案可以帮助;) – 2011-03-28 08:32:01
嗨维克多。感谢您的评论。在这个问题上我没有看到你的建议。但这看起来正是我在寻找的东西。当我回家的时候会试试这个。谢谢 – superbly 2011-03-28 08:42:29
这么多善良的话,没有一个upvote xD – 2011-03-28 09:04:25