【发布时间】:2017-03-07 18:41:58
【问题描述】:
我对 Spring Boot (1.4.1) 和 Thymeleaf (3) 中的 MessageSource 消息有疑问。
文件 app.properties
app.quotes=Francesco's title
app.quotes2=Francesco''s title
当我打印消息时在 page.html 中
<h2 th:text="#{app.quotes}"></h2>
<h2 th:utext="#{app.quotes}"></h2>
<h2 th:text="#{app.quotes2}"></h2>
<h2 th:utext="#{app.quotes2}"></h2>
我明白了(th:text 或 th:utext 没有任何区别)
- 弗朗西斯科的头衔
- 弗朗西斯科的头衔
- 弗朗西斯科的头衔
- 弗朗西斯科的头衔
在我的控制器中
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Autowired
private MessageSource messages;
@RequestMapping(value="/page", method = RequestMethod.GET)
public String page() {
String text = messages.getMessage("app.quotes", null, LocaleContextHolder.getLocale());
String text2 = messages.getMessage("app.quotes2", null, LocaleContextHolder.getLocale());
log.debug("text = " + text);
log.debug("text2 = " + text2);
// Output
return "page";
}
我记录的文本是
text = Francescos titletext2 = Francesco's title
这是可以预测的,因为属性消息中的单引号必须用双单引号转义(“Francesco's title”应该是正确的文本)。 如何让 Thymeleaf 像 MessageSource 那样打印转义双单引号的消息,或者 MessageSource 像 Thymeleaf 那样返回纯文本? 我不想根据调用者使用不同的键/值。
提前感谢您的帮助。
【问题讨论】:
标签: spring spring-boot properties internationalization thymeleaf