简体   繁体   English

Thymeleaf和Spring Boot不显示图像

[英]Thymeleaf and Spring Boot doesn't show image

Do my Spring Boot app with thymeleaf and instead of image I see only icon of image. 用百里香做我的Spring Boot应用程序,而不是图像,我仅看到图像图标。 How can I fix this? 我怎样才能解决这个问题? Image in static->images folder 图像在static-> images文件夹中

<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>

Use configuration like this. 使用这样的配置。

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

add all location from where you want to show image. 添加您要显示图像的所有位置。 dont use / after file: 不要在文件后使用/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM