我正在使用thymeleaf和springboot
我无法在HTML文件中查看任何图片。我曾尝试过各种不同的方式在百里香中做同样的事情,但没有运气。
这是我的项目文件夹结构
src
└─── main
└─── resources
├─── templates
├─── css
└─── images
HTML文件
<head>
<title>Community Bike Share Web Application</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<link rel="stylesheet" th:href="@{/webjars/bootstrap/3.1.1/css/bootstrap.min.css}" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
</head>
<div>
<img th:src="@{/images/taiwan_Bicycle_Ride_hd_wallpaper_8.jpg}"
src="../images/taiwan_Bicycle_Ride_hd_wallpaper_8.jpg" class="img-responsive" alt="Responsive image"/>
</div>
答案 0 :(得分:13)
使用Boot的默认配置,您的图像(和其他静态内容)需要位于src/main/resources/static
之下。例如,要提供/images
中的内容,请将文件放入src/main/resources/static/images
答案 1 :(得分:0)
这可能会有所帮助。我在我的应用程序中使用它,没有显示错误(至少在Mozilla中)。 使用../ ..访问应用程序中的文件和目录。
<img alt="Caption X" class="rounded-circle img-responsive mt-2"
height="128" th:src="@{/../static/images/theImage.png}" width="128">
我在Thymeleaf工作得很好。
答案 2 :(得分:0)
正如安迪·威尔金森(Andy Wilkinson)所说-
使用Boot的默认配置,您的图像(和其他静态内容)必须位于src/main/resources/static
以下。例如,要提供/images
中的内容,请将文件放入src/main/resources/static/images
并以这种方式使用
<img th:src="@{/images/image.png}" alt="image" width="300" height="200">