Spring Boot(1.4.1)和ThymileAF(3)MessageSource单引号

Spring Boot(1.4.1)和ThymileAF(3)MessageSource单引号,spring,spring-boot,properties,internationalization,thymeleaf,Spring,Spring Boot,Properties,Internationalization,Thymeleaf,我对SpringBoot(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

我对SpringBoot(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>
我记录的文本是

  • text=Francescos title
  • text2=弗朗西斯科的头衔
这是可以预测的,因为属性消息中的单引号必须用双单引号转义(“Francesco的标题”应该是正确的文本)。 如何使Thymeleaf像MessageSource那样打印转义双单引号的消息,或像Thymeleaf那样让MessageSource返回纯文本? 我不希望根据调用方使用不同的键/值


提前感谢您的帮助。

Spring不会解析消息,只要它不包含参数(
app.quote=John的消息
),但如果它有参数(
app.quote={0}的消息
),就会解析

您可以使用
setAlwaysUseMessageFormat
覆盖此行为:

@Bean
MessageSource defaultMessageSource(){
 org.springframework.context.support.ReloadableResourceBundleMessageSource source = new org.springframework.context.support.ReloadableResourceBundleMessageSource();
source.setAlwaysUseMessageFormat(true);
return source;
}

另请看。

谢谢您的回答。我已经设置了属性spring.messages.always使用message format=true,现在thymeleaf用双引号正确打印所有文本。
@Bean
MessageSource defaultMessageSource(){
 org.springframework.context.support.ReloadableResourceBundleMessageSource source = new org.springframework.context.support.ReloadableResourceBundleMessageSource();
source.setAlwaysUseMessageFormat(true);
return source;
}