html - 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>
我使用 DTO 来映射实体,但是当显示实际的 html 页面时,图像不显示(404 错误),即使在我检查标签时链接显示。
我错过了一些明显的东西吗?如果我不想将它们转换为字节流,这不是在我的页面上显示图像的简单方法吗?我猜您需要更多信息,但我不知道哪个会有所帮助。任何帮助表示赞赏!
解决方案
无法从运行在 Web 服务器上的网页访问本地文件系统。有关详细信息,请参阅此答案。
推荐阅读
- c# - 日期选择器不能使用自定义格式
- ruby-on-rails - 如何对 Rails 中的小数字段进行验证?
- android - java.lang.IllegalStateException:指定的孩子已经有一个父母。您必须先在孩子的父母上调用 removeView() 吗?
- mongodb - 无法在 MongoDB 中使用不区分大小写的搜索运行查询
- java - 这被认为是低耦合和高内聚吗?有改善的机会吗?
- jquery - 在 pdf 查看器 syncfusion 中加载 pdf
- excel - 用于调整列表对象范围引用的范围的 excel VBA
- loops - Pyspark:比较值,如果为真,则执行语句
- mapping - 合同修改映射数据时web3js发送交易失败,但重新混合工作
- micronaut - Can you alter a Micronaut App features from the command line?