最近项目需要国际化,一般常见的方式就是采用配置文件话国际化。

根据请求头传入不同的语言,返回不同的内容;

 

 

自己搭建了一个模型,分如下几步:

1.spring配置文件修改,定义国际化消息

2.查找项目中需要返回到web的国际化内容,写到配置文件中

3.处理国际化封装成一个工具类,在controller层 统一处理。

国际化需要注意,如果调用方未传language,系统需要默认一个,最好写在配置文件中,方便随时修改,用 @value注入到国际化工具类中。

 

一 :Spring配置文件

  <!-- 定义国际化消息-->
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <!-- 其中basename用来指定properties文件的通用名
              如实例中的messages_en.properties,messages_ja.properties通用名都是messages
         -->
        <property name="basename" value="messages"/>
        <property name="useCodeAsDefaultMessage" value="true" />
        <property name="defaultEncoding" value="UTF-8"/>
        <property name="cacheSeconds" value="100"></property>

    </bean>
View Code

相关文章:

  • 2021-12-26
  • 2021-08-30
  • 2022-01-06
  • 2021-09-10
  • 2022-12-23
猜你喜欢
  • 2021-10-27
  • 2021-04-07
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2021-11-07
相关资源
相似解决方案