springMVC 多語言通配符的使用

1.springMVC配置多語言

spring-MVC.XML

<bean id="messageSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="basenames">
			<list>
				<value>classpath:Language/Language</value>
			</list>
		</property>
		<property name="cacheSeconds" value="3600"/><!-- -1永不自動加載 -->
		<!-- 如果在國際化資源文件中找不到對應代碼的信息,就用這個代碼作爲名稱 -->
		<property name="useCodeAsDefaultMessage" value="true" />
	</bean>
	<!-- 國際化操作攔截器 如果採用基於(請求/Session/Cookie)則必需配置 -->
	<bean id="localeChangeInterceptor"
		class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
	</bean>
	<bean id="localeResolver"
		class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
		<!-- <property name="defaultLocale" value="en_US"/> -->
	</bean>
	<mvc:interceptors>
		<!--國際化資源切換(根據請求參數中的locale參數自動切換) -->
		<mvc:interceptor>
			<mvc:mapping path="/**" />
			<ref bean="SystemInterceptor" />
		</mvc:interceptor>
		<mvc:interceptor>
			<mvc:mapping path="/**" />
			<ref bean="localeChangeInterceptor" />
		</mvc:interceptor>
		<mvc:interceptor>
			<mvc:mapping path="/**" />
			<ref bean="themeChangeInterceptor" />
		</mvc:interceptor>
		<!-- <mvc:interceptor> <mvc:mapping path="/**" /> <ref bean="SqlInjectInterceptor"/> 
			</mvc:interceptor> -->
	</mvc:interceptors>

2.Language_zh_CN.xml

<!-- 頁面驗證 -->
<entry key="IsNoEmpty">不能爲空</entry>
<entry key="OnlyNum">只能爲數字</entry>
<entry key="Between">長度爲{0}-{1}位</entry>
<entry key="IsBlank">不能包含空格</entry>
<entry key="IsMobile">手機號碼格式不正確</entry>
<entry key="IsEmail">郵箱格式不正確</entry>
<entry key="IsConfirm">兩次填寫的密碼不一致</entry>
<entry key="IpAddress">IP地址不正確</entry>
<entry key="onlyEnAndNum">輸入英文、數字或下劃線</entry>
<entry key="Length">長度爲{0}-{1}</entry>
<entry key="Byte">位</entry>
<entry key="onlyInt">只能爲數字</entry>

3.頁面使用spring標籤

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:message code="Between" arguments="1,32" argumentSeparator=","/>

arguments屬性爲通配符匹配的值;

argumentSeparator屬性爲通配符是按照什麼格式進行分割的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章