【问题标题】:Spring : How to show image in thymeleaf from databaseSpring:如何从数据库中显示百里香中的图像
【发布时间】:2018-06-18 01:59:03
【问题描述】:

我正在使用 Spring Boot+Spring Data+Spring MVC 进行项目。我想将图像从数据库显示到 thymeleaf,但未显示图像。这是我的代码

 <span th:each="room,iterStat : ${room}">
                    <div class="col-md-3 md-col">
                        <div class="col-md">
                            <a href="single.html" class="compare-in"><img th:src="@{/static/images/${room.image}}" alt="" />

                            </a>    
                            <div class="top-content">
                                <h5><a href="single.html"><tr th:text="${room.name}"></a></h5>
                                <div class="white">
                                    <a th:href="@{/room/{id}/book(id=${room.id})}" class="hvr-shutter-in-vertical hvr-shutter-in-vertical2">BOOK</a>
                                    <p class="dollar"><span class="in-dollar">$</span><span>2</span><span>0</span></p>
                                    <div class="clearfix"></div>
                                </div>
                            </div>                          
                        </div>
                    </div>
                     </span>

我将图像名称保存在数据库中,并将图像保存在文件夹 ../static/images .. 当我在数据库中复制图像名称而不是 ${room.image} 时,图像将显示..我不知道为什么

【问题讨论】:

  • 很高兴帮助我
  • 你读过this page吗?

标签: spring thymeleaf


【解决方案1】:

我遇到了同样的问题,我通过这样做解决了问题:--

<th:style="'background-image:url('+ ${room.image}+');'"></div>

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 2018-09-07
    • 1970-01-01
    相关资源
    最近更新 更多