【问题标题】:Variables with messages带有消息的变量
【发布时间】:2015-05-13 10:11:12
【问题描述】:

我的 Spring Boot 应用程序中有一个 messages.property 文件。比如:

welcome=Hello {0} welcome to my page

现在我可以通过 thymeleaf 访问它了:

<th th:text="#{welcome(${Firstname})}"></th>

但我想做的是显示:你好 John Doe,欢迎来到我的页面。 John 和 Doe 是不同的变量,我会在欢迎信息中注入。

也许我的属性文件现在看起来像:message= Hello {0} {1}, Welcome to my page 有没有办法在 spring/thymeleaf 中实现这一点?

【问题讨论】:

  • 你不能不使用会话或cookies吗?
  • 我不想从属性文件中获取消息值,它是静态的,只能从messages.properties文件中编辑

标签: php spring spring-boot thymeleaf


【解决方案1】:

像这样更改您的属性文件:message=Hello {0}, Welcome to my page 并像这样调用标签:&lt;th th:text="#{welcome(${varialbe})}"&gt;&lt;/th&gt;

【讨论】:

  • 很好,这解决了它。但我现在已经编辑了我的问题。看看有没有办法解决这个问题。谢谢。
  • 不是 Thymeleaf 的经验,而是在 () 括号之间添加两者,由 , 分隔?
猜你喜欢
  • 1970-01-01
  • 2020-06-23
  • 2020-01-23
  • 1970-01-01
  • 1970-01-01
  • 2013-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多