W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
You can enable changing of locales by adding the LocaleChangeInterceptor
to one of the handler mappings (see [Section 21.4, "Handler mappings"](mvc.html
the request and change the locale. It calls setLocale()
on the LocaleResolver
that also exists in the context. The following example shows that calls to all *.view
resources containing a parameter namedsiteLanguage
will now change the locale. So, for example, a request for the following URL, <http://www.sf.net/home.view?siteLanguage=nl>
will change the site language to Dutch.
你可以在處理器映射(詳見Spring MVC 處理器映射小節(jié))前添加一個LocaleChangeInterceptor
攔截器來更改地區(qū)信息。它能檢測請求中的參數(shù),并根據(jù)其值相應(yīng)地更新地區(qū)信息。它通過調(diào)用LocaleResolver
的setLocale()
方法來更改地區(qū)。下面的代碼配置展示了如何為所有請求*.view
路徑并且攜帶了siteLanguage
參數(shù)的資源請求更改地區(qū)。舉個例子,一個URL為<http://www.sf.net/home.view?siteLanguage=nl>
的請求將會將站點語言更改為荷蘭語。
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="siteLanguage"/>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor"/>
</list>
</property>
<property name="mappings">
<value>/**/*.view=someController</value>
</property>
</bean>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: