简体   繁体   中英

image is not showing in html thymeleaf springboot

I am using thymeleaf along with springboot

 I am not able to view any images in my HTML file. I have tried all different ways of doing 
 the same in thymeleaf but no luck.

 Here is my project folder structure

   🗁 src
    └─── 🗁 main
            └─── 🗁 resources
                      ├─── 🗁 templates
                      ├─── 🗁 css
                      └─── 🗁 images

In HTML File i use:

 <img src="/src/main/resources/static/image.png" alt="images">

After try many thing finally i got the answer

Spring Boot's default configuration come that, your images (and other static 
content), need to be in src/main/resources/static. For example, to serve content 
from /images put the files in src/main/resources/static/images

And i used it

<img th:src="@{/images/image.png}" alt="image" width="300" height="200">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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