首页 > 解决方案 > Springboot:使用数据库中的链接在html上显示图片

问题描述

我正在使用 springboot 和 thymeleaf 映射以在 html 页面上显示我的数据库中的数据。

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
<title></title>
<link rel="stylesheet" type="text/css" th:href="@{/assets/style.css}" />

</head>
<body>
    <p th:text="${title}"></p>

    <a href="/newPost">Create a new Post</a>
    <a href="/newComment">Create a new Comment</a>


    <table>
        <tr th:each="post : ${posts}">
            <td th:text="${post.creationDate}"></td>
            <td th:text="${post.titel}"></td>
            <td th:text="${post.content}"></td>
            <td><a th:href="@{/newComment(postId=${post.id})}">new Comment</a></td>
            <td th:text="${post.comments}"></td>
            <td><img th:src="${post.bild}"></td>
        </tr>
    </table>

海蒂SQL

我使用 DTO 来映射实体,但是当显示实际的 html 页面时,图像不显示(404 错误),即使在我检查标签时链接显示。在此处输入图像描述

我错过了一些明显的东西吗?如果我不想将它们转换为字节流,这不是在我的页面上显示图像的简单方法吗?我猜您需要更多信息,但我不知道哪个会有所帮助。任何帮助表示赞赏!

标签: htmlmysqlspring-bootthymeleafheidisql

解决方案


无法从运行在 Web 服务器上的网页访问本地文件系统。有关详细信息,请参阅此答案


推荐阅读