Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display jpg from db web page?

Tags:

thymeleaf

I have got table and display datas from database (mysql). I use thymeleaf. All fields are ok but sb.cover doesnt show jpg (blob column in my database). Have you got any ideas how to put jpg in web page using thymeleaf? Thanks

<tr th:each="sb, poz : ${product}">
    <td th:text="${poz.count}">1</td>
    <td th:icon="${sb.cover}"></td>
    <td th:text="${sb.title}"></td>
    <td th:text="${sb.price}"></td>
    <td ><b><a th:href="@{/details}">DETAILS</a></b></td>
    <td ><b><a th:href="@{/cart}">ADD TO CART</a></b></td>
    </tr>
like image 852
user978758 Avatar asked Jul 21 '13 13:07

user978758


2 Answers

It's worked for me:

<img class="info" th:attr="src=@{${image}}" />

where 'image' is base64 image:

image = "data:image/png;base64,R0lGODlhlgCWAMQAAPz.........

in Spring Java Controller:

@RequestMapping(value = "/get_goods_detail", method = RequestMethod.GET)
public String getGoodsDetail(@RequestParam(value = "itemid") final int itemid,
                             ModelMap model) {
    // get image
    String image = "data:image/png;base64,R0lGODlhlgCWAMQAAPz8/N3d3eX.../big image

    model.addAttribute("image", image);
    return  "goods_detail";  // return name of html view with thymeleaf
}
like image 198
user3825510 Avatar answered Sep 28 '22 02:09

user3825510


I am not sure this will help you...

<tr th:each="sb, poz : ${product}">
    <td th:text="${poz.count}">1</td>
   <td><img  th:attr="src=@{${sb.cover}} , title=#{background}, alt=#{background}" style="width: 150px; height: 150px;" /></td> 
    <td th:text="${sb.title}"></td>
    <td th:text="${sb.price}"></td>
    <td ><b><a th:href="@{/details}">DETAILS</a></b></td>
    <td ><b><a th:href="@{/cart}">ADD TO CART</a></b></td>
    </tr>
like image 33
Prasanth A R Avatar answered Sep 28 '22 01:09

Prasanth A R