【问题标题】:anchor text url is not showing as link in th:text thymleaf锚文本 url 未在 th:text thymeleaf 中显示为链接
【发布时间】:2020-01-23 14:09:17
【问题描述】:

我将一些文本转换为显示为链接,它来自后端,但在 UI 中它不显示为链接。 我正在使用 thymelaf 来呈现 p 标签内的文本。请在下面找到代码:

html 文件:

 <div class="column" style="margin-left: auto; margin-right: auto; float: none;" th:each="pre:${prrMap}"> 
     <div class="prerequisite" align="center">
              <label class="prerequisite" th:text="${pre.key}"></label>
              <p class="prerequisite" id="prerequisite" th:text=${pre.value}></p>
      </div>
  </div>

th:text=${pre.value} 包含具有锚文本的字符串。

示例:${pre.value} = "先决条件:测试数据{a href="https://ecom-test-data.index.html"}测试链接{/a} 链接已创建 数据但不显示为链接”

这里不能包含锚文本标签,所以使用了{} = ,它显示在前端。

异常输出:先决条件:测试数据test link链接 已创建数据但未显示为链接

【问题讨论】:

    标签: javascript jquery html spring-boot thymeleaf


    【解决方案1】:

    如果您希望输出未转义的 html,请使用 th:utext(而不是 th:text)。

    【讨论】:

    • 谢谢,它可以工作,但它不适用于新行。在开发工具中它显示正确,但在 UI (chrome) 中显示不一样。将字符串转换为在 html 中看起来不错有很多问题。
    • 如果你想换行,你必须使用&lt;br /&gt;。 Html 不保留空格。
    猜你喜欢
    • 2021-12-09
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多