如何从db网页显示jpg? [英] How to display jpg from db web page?

查看:41
本文介绍了如何从db网页显示jpg?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从数据库 (mysql) 获得了表格和显示数据.我用百里香.所有字段都可以,但 sb.cover 不显示 jpg(我的数据库中的 blob 列).您知道如何使用 thymeleaf 在网页中放置 jpg 吗?谢谢

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>

推荐答案

它对我有用:

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

其中图像"是 base64 图像:

where 'image' is base64 image:

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

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

在 Spring Java 控制器中:

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
}

这篇关于如何从db网页显示jpg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆