spring 國際化配置
阿新 • • 發佈:2019-02-18
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource
<property name="basenames">
<list>
<value>message</value>
<value>mess</value>
<value>messages</value>
</list>
</property>
<property name="defaultEncoding" value="utf-8"></property>
</bean>
<!-- <bean id="guojihua" class="com.zdc.Guojihua">
<constructor-arg name="name" value="大豪門" type="java.lang.String"></constructor-arg>
</bean> -->
</beans>
1、bean 中載入的類是固定的,只需寫入進去即可;
2、檢視spring api可以發現
有setBasename(配置一個.properties檔案)和setBasenames(配置多個.properties檔案)。bean中property標籤就是Java類中的set方法。所以該種配置是載入過個.properties檔案。這三個.propertis檔案表示三種類型。messs_en_US.propertis表示美國英語,在bean中配置可以省略_en_us只取mess作為值。message_zh_CN.properties表示中國漢語。messages.properties表示普通的.propertis檔案。
呼叫方式:
途中佔位符對應下圖{0}