【问题标题】:Thymeleaf and Spring Boot doesn't show imageThymeleaf 和 Spring Boot 不显示图像
【发布时间】:2019-01-02 12:19:25
【问题描述】:

使用百里香做我的 Spring Boot 应用程序,而不是图像,我只看到图像的图标。我怎样才能解决这个问题? 静态图片->图片文件夹

<table class="table table-striped">
    <tr th:each="message : ${messages}">
        <td th:text="${message.id}"></td>
        <td th:text="${message.text}"></td>
        <td th:text="${message.tag}"></td>
        <td><img th:src="@{/images/thymeleaf.png}"/></td>
    </tr>
</table>

【问题讨论】:

  • 给出你的 webmvc 配置
  • public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/img/**") .addResourceLocations("file://" + uploadPath + "/"); registry.addResourceHandler("/static/**") .addResourceLocations("classpath:/static/");}

标签: java image spring-mvc spring-boot thymeleaf


【解决方案1】:

使用这样的配置。

public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/img/**").addResourceLocations("file:resources/","file:images/","file:" + uploadPath + "/");
    registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}

添加您要显示图像的所有位置。 不要在 file:

之后使用 /

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 2023-01-02
    • 2019-09-27
    • 2019-01-31
    • 2020-11-28
    • 1970-01-01
    相关资源
    最近更新 更多