【问题标题】:Spring: Not display image in thymeleaf春天:不在百里香中显示图像
【发布时间】:2018-11-27 22:59:04
【问题描述】:

我正在做 Spring 项目,使用 Spring Boot、Spring MVC、Spring Data。现在我有一个问题,也许是百里香叶 这是我的索引页

Logo Bonfire 和房间图片是图像并保存在 eclipse 中的文件夹 src/main/resource/static/images 中。

当我使用搜索功能时,它会显示如下图所示的搜索页面

我不知道为什么它不显示徽标图像和房间图像,虽然我为我的索引页面和搜索页面使用了一个模板......而且它仍然发生在详细页面上,没有显示图像。仅索引页显示图片

我认为问题不在于代码...我不知道为什么 这是我的room.html(索引页和搜索页)

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="Header :: head">
</head>
<body>
<div th:replace="Header :: header"  class="header"></div>
<div class="container">
        <div class="products">
                <h2 class=" products-in">AVAILABLE ROOM</h2>
                <div class=" top-products">
                 <span th:each="room,iterStat : ${room}">
                    <div class="col-md-3 md-col">
                        <div class="col-md">
                            <a th:href="@{/room/{id}/detail(id=${room.id})}" class="compare-in"><img th:src="@{'images/'+${room.image}}" alt="" />

                            </a>    
                            <div class="top-content">
                                <h5><a th:href="@{/room/{id}/detail(id=${room.id})}"><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>
                <div class="clearfix"></div>
                </div>

        </div>
    </div>
 <div th:replace="Header :: footer"   class="footer"></div>

 </body>
 </html>

帮帮我

【问题讨论】:

  • 有人可以帮我T.T
  • 尝试使用Chrome浏览器的Inspect功能(或其他浏览器中的任何替代)。因此,打开页面的代码,并检查图像的路径。他们是对的吗?
  • @VadimBeskrovnov 我检查了图像的路径。我觉得是对的,你可以看到索引页面显示的图像,而搜索页面并不认为两个页面都使用一个模板。我不知道为什么
  • 索引页和搜索页的图片路径是否相同?
  • 请检查索引页和搜索页是否在同一根目录。

标签: spring spring-boot thymeleaf


【解决方案1】:

使用这种方法设置图像:--

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

【讨论】:

    【解决方案2】:

    使用类似的东西。

    <img th:src="${'images/'+ room.image}" />
    

    【讨论】:

      猜你喜欢
      • 2015-12-09
      • 1970-01-01
      • 2014-06-04
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 2018-05-23
      • 1970-01-01
      相关资源
      最近更新 更多