Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 如何通过FreeMarker中的属性文件加载标签_Spring Mvc_Freemarker_Labels - Fatal编程技术网

Spring mvc 如何通过FreeMarker中的属性文件加载标签

Spring mvc 如何通过FreeMarker中的属性文件加载标签,spring-mvc,freemarker,labels,Spring Mvc,Freemarker,Labels,我正在使用SpringMVC+FreeMarker集成。由于我是FreeMarker的新手,我无法找到从属性文件配置FreeMarker标签的方法 请帮我解决这个问题 谢谢。您可以为此使用“ResourceBundleMessageSource”消息源 <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" <

我正在使用SpringMVC+FreeMarker集成。由于我是FreeMarker的新手,我无法找到从属性文件配置FreeMarker标签的方法

请帮我解决这个问题


谢谢。

您可以为此使用“ResourceBundleMessageSource”消息源

<bean id="messageSource"   
           class="org.springframework.context.support.ResourceBundleMessageSource"
      <property name="basename" value="classpath:messages/messages" />
      <property name="defaultEncoding" value="UTF-8"/>
/>

定义区域设置解析器

<bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        <property name="defaultLocale" value="en" />
    </bean>

定义localeChangeInterceptor,它从用户会话检测语言参数并调用LocaleResolve。并在处理程序映射中注册拦截器

<bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang" />
</bean>

class=“org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping”>
属性文件需要定义如下:

  • 消息属性
  • 消息属性
在messages文件夹路径中

如果语言属性文件经常更改,则可以使用“ReloadableResourceBundleMessageSource”。这意味着您不必在每次语言文件更改时重新启动应用程序

您需要导入spring宏

<#import "/spring.ftl" as spring/>

可以在.ftl中访问消息,如下所示

<@spring.message "customMessageKey"/> 


它如何决定使用消息属性或消息属性?检查更新的答案。拦截器提供LocalResolver中使用的语言参数。
<@spring.message "customMessageKey"/>