Thymeleaf Server相对URL未按预期工作

时间:2016-05-22 02:34:08

标签: java spring thymeleaf

我将一些图片上传到我的webapp上下文之外的文件夹中。现在,我需要显示这些图像,我试过这个:

 <img class="profile-user-img img-responsive img-circle" th:src="@{~/my-server-path/Logo-Free.jpg}" alt="Logo"/>

这不起作用,因为在localhost中寻找图像:8080 / my-server-path / Logo-Free.jpg。

我需要的是在/my-server-path/Logo-Free.jpg中找到图像。

我也试过这样的事情:

<img class="profile-user-img img-responsive img-circle" th:src="@{file:///my-server-path/Logo-Free.jpg}" alt="Logo"/>

但是没有用,有人能给我一个关于如何显示位于我服务器中的图像的建议吗?

1 个答案:

答案 0 :(得分:0)

在dispatcher-servlet中定义mvc资源映射,如下所示: -

<mvc:resources mapping="/images/**" location="file:/home/images/" />

然后像下面这样引用网址: -

<img class="profile-user-img img-responsive img-circle" th:src="@{file:///my-server-path/images/Logo-Free.jpg}" alt="Logo"/>