html - 如何在 Thymeleaf 中配置基本 URL?

标签 html spring-mvc thymeleaf

我将 Thymeleaf 用于 Web 应用程序的模板。

当我创建链接时,我使用这样的 URL:

<img class="info" 
    src="../../../resources/img/image.png"
    th:src="@{/resources/img/image.png}" /> 

如何在 Thymeleaf 中配置基本 URL?

我需要它,因为我的应用程序在当前 URL 中运行:

http://localhost:8080/myapp

它工作正常,但随后它重定向到:

http://www.myapp.com/

然后图像被搜索到:

http://www.myapp.com/myapp/resources/img/image.png

代替:

http://www.myapp.com/resources/img/image.png

我想要这样的东西:

<property name="baseURL" value="http://www.myapp.com"/>

最佳答案

尝试 Server-relative URLs :

<img class="info" th:src="@{~/resources/img/image.png}" />

更新
实际链接到 url part of Thymeleaf 2.1. tutorial

关于html - 如何在 Thymeleaf 中配置基本 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18651119/

相关文章:

html - 使用纯 css 格式化单词

java - 如何使用 Jsoup 在元素之前插入标签

spring-boot - Thymeleaf 如何为 Google Chart 输出对象数组

java - 删除时不支持请求方式GET

spring - Thymeleaf 不会获取页面

javascript - JQuery 点击事件仅在第一次工作

javascript - 如果选择"is"单选按钮,则需要 jQuery 或 JavaScript 验证

java - 具有自定义状态代码的 Spring Boot Controller ?

java - Spring bean java.lang.NoSuchMethodError 错误

Spring @Configuration类,如何配置传递不同参数的同一个bean的多个实例