gpt4 book ai didi

java - 如何在页面上添加图片

转载 作者:行者123 更新时间:2023-12-02 08:55:22 27 4
gpt4 key购买 nike

我想将图片添加到我的表格中。但它没有出现在页面上。我没有收到任何错误。如何在index.html 中指定图像字段的地址?

图片已上传至数据库:

enter image description here

但在页面上不可见:

enter image description here

index.html

<body>

<div layout:fragment="content" class="py-5">
<div class="container">
<h2 style="text-align: center">Список ваших объявлений</h2>
<div class="col-md-12">

<table class="table">
<thead class="thead-light">
<tr>
<th>ID</th>
<th>Description</th>
<th>Price</th>
<th>Sold</th>
<th>Body</th>
<th>Brand</th>
<th>Engine</th>
<th>Model</th>
<th>Image</th>
</tr>
</thead>
<tbody>
<th:block th:each="order : ${orders}" th:remove="tag">
<tr>
<td th:text="${order.id}"></td>
<td th:text="${order.description}"></td>
<td th:text="${order.price}"></td>
<td th:text="${order.sold}"></td>
<td th:text="${order.body}"></td>
<td th:text="${order.brand}"></td>
<td th:text="${order.engine}"></td>
<td th:text="${order.model}"></td>
<td>
<a href="#" class="thumbnail">
<img th:src="@{/general/{id}/image(id = ${order.getId()})}" th:width="350" th:height="350"/>
</a>
</td>


</tr>
</th:block>
</tbody>
</table>

<p>
<a th:href="@{/general/showFormForAdd}" class="btn btn-outline-info btn-lg my-3">Новое объявление</a>
</p>

</div>
</div>
</div>

</body>

图像位于订单 - byte[] 图像中。代码如下

@Entity @Table(name = "orders") public class Orders {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;

@Column(name = "description")
private String description;

@Column(name = "price")
private int price;

@Column(name = "sold")
private boolean sold;

@Column(name = "body")
private String body;

@Column(name = "brand")
private String brand;

@Column(name = "engine")
private String engine;

@Column(name = "model")
private String model;

@Lob
@Column(name = "image")
private byte[] image;

@Column(name = "str")
private String imageStr;


public Orders() {
}

public Orders(int id) {
this.id = id;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public boolean isSold() {
return sold;
}

public void setSold(boolean sold) {
this.sold = sold;
}

public int getPrice() {
return price;
}

public void setPrice(int price) {
this.price = price;
}

public String getBody() {
return body;
}

public void setBody(String body) {
this.body = body;
}

public String getBrand() {
return brand;
}

public void setBrand(String brand) {
this.brand = brand;
}

public String getEngine() {
return engine;
}

public void setEngine(String engine) {
this.engine = engine;
}

public String getModel() {
return model;
}

public void setModel(String model) {
this.model = model;
}

public byte[] getImage() {
return image;
}

public void setImage(byte[] image) {
this.image = image;
}

public String getImageStr() {
return imageStr;
}

public void setImageStr(String imageStr) {
this.imageStr = imageStr;
} }

最佳答案

所以你可以做这样的事情

<img src="data:image/png;base64,${order.getImage()}">

关于java - 如何在页面上添加图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60524675/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com