【发布时间】:2011-03-27 10:37:11
【问题描述】:
我有一个 JDO 类和一个帮助类 Image 来将图像存储在一个字节数组中
JDO 类:
@PersistenceCapable
class Recipe{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long key
@Persistent
private String description
@Persistent(serialized = "true")
private 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 页面中显示字节数组中的图像?
【问题讨论】:
-
对我来说看起来像是 stackoverflow.com/questions/4502278/… 的副本。我的回答可能会有所帮助;)
-
你好维克多。感谢您的评论。我没有看到你在这个问题上的建议。但这看起来正是我正在寻找的。回家的时候试试这个。谢谢
-
这么多好话,没有一个赞xD