gpt4 book ai didi

java - 我正在尝试根据 thymeleaf 中 pojo 的 id 获取特定图像

转载 作者:行者123 更新时间:2023-12-02 05:25:24 27 4
gpt4 key购买 nike

问题就出在这里。我正在尝试从对象的 id 中获取文件夹。例如,我想要 images/1/1.jpg 中的照片prop.id 具有该属性的 id,该属性的照片将在 images/{id} 文件夹中。

<img class="card-img-top" src="images/${prop.id}/1.jpg" alt="Card image cap">
Property property = new Property(1,null,"description single", null);

@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView messages(Model model) {
PropertiesDao prop = new PropertiesDao();
List<Property> x= prop.getAll();
ModelAndView mav = new ModelAndView("newhome");
model.addAttribute("multipleProperty",x );
model.addAttribute("property", property);
return mav;
}

这是我正在尝试工作的代码。Property 类具有我目前感兴趣的 id 和说明。我希望根据 id 来获取 resources/static/images/1 中名为 1 的特定文件夹

<div class="col-sm-3" th:each="prop: ${multipleProperty}">
<div class="card">
<img class="card-img-top" src="images/${prop.id}/1.jpg" alt="Card image cap">
<div class="card-body">
<h4 class="card-title" th:text="${prop.description}">Sample Card Title</h4>
<p class="card-text" th:text="${prop.id}">He seems sinking under the evidence could
not only grieve and a visit. The father is to bless and placed in
his length hid...</p>
<a href="#" class="btn btn-primary">Tell me more &rarr;</a>
</div>
</div>
</div>
package com.generic.components;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

public class Property {

private int id;
private List<String> images;
private String description;
private List<Rooms> rooms;
public Property(int id, List<String> images, String description, List<Rooms> rooms) {
super();
this.id = id;
this.images = images;
this.description = description;
this.rooms = rooms;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public List<String> getImages() {
return images;
}
public void setImages(List<String> images) {
this.images = images;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<Rooms> getRooms() {
return rooms;
}
public void setRooms(List<Rooms> rooms) {
this.rooms = rooms;
}
@Override
public String toString() {
return String.format("Property [id=%s, images=%s, description=%s, rooms=%s]", id, images, description, rooms);
}



}

我已成功从对象中提取变量 id,但我无法使 thymeleaf 将 images/${prop.id}/1.jpg 识别为 images/1/1.jpg

最佳答案

您应该为 img src 添加th::

<img class="card-img-top" th:src="${'images/' + prop.id + '/1.jpg'}" alt="Card image cap">

关于java - 我正在尝试根据 thymeleaf 中 pojo 的 id 获取特定图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56236379/

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