0

How could I display images from a list of collection, which retrieved images from mysql db and has contents of images in bytes.

@RequestMapping(value = "media-nenuid/{menuid}", method=RequestMethod.GET)
public String postmedia(Model model, @ModelAttribute Imagefile 
newimgfile,@PathVariable int menuid ) {

 Menu menu = menuDao.findOne(menuid);//this find the menu with id passed in.
List<Imagefile> imagefiles = menu.getImagefiles();//then imagefiles has 
filenames, and images' content of that menuid.

model.addAttribute("imagefiles", menu.getImagefiles());//passing to thymeleaf.

return "Imagefile/media-menuid"; }

Syntax in thymeleaf.

<table class="table">
 <tr th:each="image : ${imagefiles}">
<td><img th:src="@{${image.imagecontent}}"></img></td>
</tr>
</table>

Under Chrome inspect, image display error.

 <tr> 
   <td>
 <img src="[B@8f0d25">
 </td>
 /tr>
aguy01
  • 13
  • 1
  • 3
  • 7
  • wanted to add that not using jsp, xml, maven. still duplicate? – aguy01 Jun 04 '17 at 15:54
  • Yes. If you ask how to go from LA to San Francisco using a motorcycle, and I'm pointing you to an answer explaining how to do it by car, you should understand that the answer also applies to motorcycles. The duplicate I linked to clearly explains that the src attribute must be a **URL** (whatever your server-side technology is), that this URL must be mapped to a resource that reads **one image** from the database (whatever your server-side technology is), and sends back the data, with the appropriate content type, to the browser. – JB Nizet Jun 04 '17 at 16:04
  • In this tag `` , `{image.getId()}` intends to pass a String id from view to a method. Method then takes the `{image.getId()}` and work on convert String id into int. is the conversion possible? – aguy01 Jun 15 '17 at 04:45

0 Answers0