Я пытаюсь получить конкретное изображение на основе идентификатора pojo в тимелист - PullRequest
0 голосов
/ 21 мая 2019

Проблема здесь. Я пытаюсь получить папку с идентификатором объекта. Например, я хотел бы фото с картинки / 1 / 1.jpg У prop.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 имеет идентификатор и описание, которые меня интересуют в данный момент. Я хотел бы, чтобы это основывалось на идентификаторе, чтобы получить определенную папку с именем 1 в resources / static / images / 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 из объекта, но я не могу заставить тимелист распознавать изображения / $ {prop.id} /1.jpg как изображения / 1 / 1.jpg

1 Ответ

0 голосов
/ 21 мая 2019

Вы должны добавить th: для img src:

<img class="card-img-top" th:src="${'images/' + prop.id + '/1.jpg'}" alt="Card image cap">
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...