【问题标题】:Accessing properties file in Spring from Thymeleaf从 Thymeleaf 访问 Spring 中的属性文件
【发布时间】:2021-03-15 20:21:08
【问题描述】:

我有一个带有这个表达式的 Thymeleaf 模板:

 <div class="box small">
                                <img th:src="'${@environment.getProperty('pics.path')} + '/' + ${user.id} + '/' + ${pic}"/>
                            </div>

但我有这个错误:

Could not parse as expression: "'${@environment.getProperty('pics.path')} + '/' + ${user.id} + '/' + ${pic}" (template: "joan" - line 528, col 38)

【问题讨论】:

    标签: java html spring-boot spring-mvc thymeleaf


    【解决方案1】:

    您的 Thymeleaf 表达式中存在语法错误 - 第一个 ' 不正确。

    这应该可行:

    <div class="box small">
      <img th:src="${@environment.getProperty('pics.path')} + '/' + ${user.id} + '/' + ${pic}"/>
    </div>
    

    当使用literal substitutions 创建复杂字符串时更易读 - 这是您使用此语法的示例:

    <div class="box small">
      <img th:src="|${@environment.getProperty('pics.path')}/${user.id}/${pic}|"/>
    </div>
    

    【讨论】:

      猜你喜欢
      • 2012-09-29
      • 1970-01-01
      • 2018-12-25
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      • 2015-03-22
      相关资源
      最近更新 更多