Can't load image with spring boot thymeleaf

后端 未结 4 846
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 15:42

I\'m very new to spring boot and following Guru spring framework tutorial.

My simple spring boot application runs successfully and my controller works fine. I have us

相关标签:
4条回答
  • 2020-12-18 15:45

    Try changing to

    <img src="../static/images/pirate.jpg" width="1000" th:src="@{images/pirate.jpg}"/>
    
    0 讨论(0)
  • 2020-12-18 15:49

    All the resources are stored in static folder and that is the default directory. You don't need to specify the relative path of the image you want to use. Just simply put the filename.

    example

    0 讨论(0)
  • 2020-12-18 15:54

    I had the same problem and when I remove leading slash it works

    <img th:src="@{images/TacoCloud.png}" />
    
    0 讨论(0)
  • 2020-12-18 16:03

    In img tag the attribute th:src's value is pointing to incorrect path, it should be th:src="@{images/pirates.jpg}" instead of th:src="@{../static/images/pirates.jpg}"

    <img src="../static/images/pirates.jpg" width="1000"
                 th:src="@{images/pirates.jpg}"/>
    

    Check the final path in the rendered HTML in browser by viewing the source

    0 讨论(0)
提交回复
热议问题