图片未显示使用百里香和春天 [英] Image does not show using thymeleaf and spring

查看:135
本文介绍了图片未显示使用百里香和春天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图片在以下目录中:

/src/main/resources/static/images/logo.png

这是我的HTML标记:

And this is my HTML tag:

<img width="220px" height="70px" th:src="@{/static/images/logo.png}"/> 

但是,当我尝试访问图像时,出现此错误:

However, when i'm trying to access the image, this error shows up:

发生意外错误(类型=未找到,状态= 404).没有讯息可用

There was an unexpected error (type=Not Found, status=404). No message available

推荐答案

您在路径中不需要 static .您应该使用 @ {/images/logo.png} ,因为默认解析器会将/src/main/resources/static/映射到/ url根据您的情况.

You don't need static in the path. You should use @{/images/logo.png}, because default resolver maps /src/main/resources/static/ to / url in your case.

来自

默认情况下,Spring Boot将提供目录中的静态内容称为/static (或/public /资源/META-INF/资源)类路径或从ServletContext的根开始.

By default Spring Boot will serve static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath or from the root of the ServletContext.

这篇关于图片未显示使用百里香和春天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆