【问题标题】:Thymeleaf: concatenate expressionsThymeleaf:连接表达式
【发布时间】:2020-12-30 06:23:42
【问题描述】:

我有这个表情

<h2 class="topmargin_0 bottommargin_30" th:text="${user.name} || ${user.age} || ' years old'"></h2>

但当我运行应用程序时。我有这个错误:

Could not parse as expression: 

【问题讨论】:

  • This 是一个很好的参考页面,它总结了许多核心 Thymeleaf 语法​​。字符串连接包含在那里。我经常提到它。
  • 如果你也在使用 Spring,那么 this 是 SpEL 的一个很好的参考。

标签: html thymeleaf


【解决方案1】:

要连接,请使用+:

<h2 th:text="${user.name} + ${user.age} + 'years old'" ...>

或者使用|:

<h2 th:text="|${user.name} ${user.age} years old|" ...>

更新: 我写了a blog post 来深入展示所有可能的字符串连接选项。

【讨论】:

    猜你喜欢
    • 2013-04-13
    • 2019-04-19
    • 1970-01-01
    • 2021-11-15
    • 2014-03-30
    • 2019-01-04
    • 2012-09-14
    • 1970-01-01
    相关资源
    最近更新 更多