Spring Boot(1.4.1)和ThymileAF(3)MessageSource单引号
我对SpringBoot(1.4.1)和Thymeleaf(3)中的MessageSource消息有一个问题 文件app.propertiesSpring 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
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=弗朗西斯科的头衔
提前感谢您的帮助。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;
}