W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
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é))前添加一個(gè)LocaleChangeInterceptor
攔截器來更改地區(qū)信息。它能檢測(cè)請(qǐng)求中的參數(shù),并根據(jù)其值相應(yīng)地更新地區(qū)信息。它通過調(diào)用LocaleResolver
的setLocale()
方法來更改地區(qū)。下面的代碼配置展示了如何為所有請(qǐng)求*.view
路徑并且攜帶了siteLanguage
參數(shù)的資源請(qǐng)求更改地區(qū)。舉個(gè)例子,一個(gè)URL為<http://www.sf.net/home.view?siteLanguage=nl>
的請(qǐng)求將會(huì)將站點(diǎn)語言更改為荷蘭語。
<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號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: