Java Thymeleaf:属性文件中的占位符

Java Thymeleaf:属性文件中的占位符,java,html,spring,spring-boot,thymeleaf,Java,Html,Spring,Spring Boot,Thymeleaf,我有一个SpringBoot应用程序。对于Thymeleaf,对于此属性文件: signup.form.error.file.too.big=File ${fileName} is too Big 在控制器上: if (Objects.nonNull(fileExceedsTheconfiguredMaximum)) { hasErrors = true; model.addAttribute("fileName", fil

我有一个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}" />

您需要对代码进行一些更改

更改消息属性,如下所示:

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})}" /> 

  • {filename}
    开始文件名不会有帮助。您可以使用
    ${fileName}
    添加文件名

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