【问题标题】:Thymeleaf: placeHolders in property filesThymeleaf:属性文件中的占位符
【发布时间】:2021-04-03 10:16:56
【问题描述】:

我有一个 SpringBoot 应用程序。使用 Thymeleaf,使用此属性文件:

signup.form.error.file.too.big=File ${fileName} is too Big 

在控制器上:

if (Objects.nonNull(fileExceedsTheconfiguredMaximum)) {
            hasErrors = true;
            model.addAttribute("fileName", fileExceedsTheconfiguredMaximum.getOriginalFilename());
        }

在模板上:

 <li th:if="${fileToBig}"  th:text="#{signup.form.error.file.too.big}" />

但我在浏览器上看到了这个:

File ${fileName} is too Big

【问题讨论】:

标签: java html spring spring-boot thymeleaf


【解决方案1】:

#{fileName} 开头的文件名无济于事。您可以使用${fileName} 添加文件名。

<li th:if="${fileToBig}" th:text="#{signup.form.error.file.too.big(${fileName})}" />

Alternative answer.

【讨论】:

    【解决方案2】:

    您需要对代码进行几处更改。

    如下更改消息属性:

    signup.form.error.file.too.big=File {0} is too Big 
    

    另一个变化是在 thymeleaf 模板文件中:

     <li th:if="${fileToBig}"  th:text="#{signup.form.error.file.too.big(${fileName})}" /> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-18
      • 2013-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      相关资源
      最近更新 更多