Display image in Spring MVC
What is the proper way , using MultiActionController? I got in my Restaurant class:
private byte[] logo;
In my database I got table BLOB image. By using hibernate, it saves to my database properly by:
<tr>
<td>Logo :</td>
<td>< inpu开发者_运维技巧t type="file" name="logo" /></td>
</tr>
But i dont know how to shows this image on another site. Maybe:
< img src="<%=("restaurant.logo")%>" alt="Upload Image" />
?
You should do something like this, create a new field in your Restaurant and have the byte[] converted to Image and use that field.
If I understand your problem, you need a controller getting your picture from database and returning it as a stream to web browser.
You can for example map controller method with request: /restaurant/logo/{id}
Then you should just type
<img src="<c:url value='/restaurant/logo/${restaurant.id}' />" alt="Upload Image" />
I you add more of code, I'll be able to give you more hints.
Please do have a look here!
This is more generic and points at all types of files upload and download.
精彩评论