I want to loop through this class and display in a table. what is the easiest way to display the image?
class Crop {
static hasMany = [diseases: Disease]
int id
String commonName
String scientificName
byte[] image
}
static mapping = {
table: 'Crops'
commonName length : 100
scientificName length: 100
image sqlType: "longblob"
}
You could do the same thing as in this answer.
Or you can create controller which provide image data stream from your entity. On GSP you could write:
<img src="${request.contextPath}/imageController/actionName?id=${entity.id}" ...
But this is unusual - storing images in entities as byte[]
. You should consider changing it to String
which would indicate a path/filename of the image.