我想使用 grails 将图像保存并显示到 oracle 10g 中的 blob 字段中。如果我在数据库中使用 Long raw 字段,那么它可以工作。但在 blob 字段的情况下,它会保存但不会显示在视图页面中。
这是代码:
//Domain
class Hotel{
byte [] pic_
static mapping={}
static constraints = {}
}
//Controller
Class contrl
{
def save() {
def hotelInstance = new Hotel(params)
if (!hotelInstance.save(flush: true)) {
render(view: "create", model: [hotelInstance: hotelInstance])
return
}
flash.message = message(code: 'default.created.message', args: [message(code: 'hotel.label', default: 'Hotel'), hotelInstance.id])
redirect(action: "show", id: hotelInstance.id)
}
}
def displayLogo () {
def sponsor = Hotel.get(params.id)
response.contentType = "image/jpg"
response.contentLength = sponsor?.pic_.length
response.outputStream.write(sponsor?.pic_)
response.outputStream.flush()
}
//View
<td><img src="${createLink(action:'displayLogo ', id:hotelInstance?.id)}" height="42" width="42" /> </td>