【问题标题】:Spring Thymeleaf doesn't process inline text variablesSpring Thymeleaf 不处理内联文本变量
【发布时间】:2017-09-13 23:05:30
【问题描述】:

我在 Thymeleaf 的文档中发现,可以在 http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#inlining 中使用内联文本变量。

当我试图用这样的代码显示我的变量的值时

<div>[[${myVar}]]</div>

它在渲染页面上显示&lt;div&gt;[[${myVar}]]&lt;/div&gt;,但如果我使用

<div th:utext="${myVar}"></div>

它在页面上显示&lt;div&gt;VALUE_OF_THE_VAR&lt;/div&gt;

我在 SpringTemplateEngine 中启用了 SpringStandardDialect()。

如何让 Thymeleaf 处理这样的内联?

非常感谢!

【问题讨论】:

    标签: spring spring-mvc thymeleaf


    【解决方案1】:

    来自您链接的同一 documentation

    为了使内联工作,我们必须使用 th:inline 属性,具有三种可能的值或模式(文本、 javascript 和无)。让我们试试文字:

    在你的情况下,它应该是这样的:

    <div th:inline="text">[[${myVar}]]</div>
    

    【讨论】:

      猜你喜欢
      • 2014-06-03
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2017-03-08
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      相关资源
      最近更新 更多