如何在Spring MVC中使用带有Freemarker的消息?
问题内容:
在.jsp文件中,我将使用:
<fmt:message key="welcome.title"/>
显示我的messages.properties文件中的消息。
我将如何用freemarker做到这一点?
问题答案:
导入弹簧宏
<#import "/spring.ftl" as spring/>
然后
<@spring.message "yourMessageKeyGoesHere"/>
但是 您需要注册ResourceBundleMessageSource
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"/>
</bean>
请记住,MessageSource 必须称为 messageSource