【问题标题】:Springboot: Displaying pictures on html by using the link out of a databaseSpringboot:使用数据库中的链接在html上显示图片
【发布时间】:2020-04-19 05:21:36
【问题描述】:

我正在使用 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>

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

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

【问题讨论】:

    标签: html mysql spring-boot thymeleaf heidisql


    【解决方案1】:

    无法从运行在 Web 服务器上的网页访问本地文件系统。详情请见this answer

    【讨论】:

      猜你喜欢
      • 2019-03-06
      • 1970-01-01
      • 2013-08-28
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      相关资源
      最近更新 更多