99re热视频这里只精品,久久久天堂国产精品女人,国产av一区二区三区,久久久精品成人免费看片,99久久精品免费看国产一区二区三区

Spring MVC 了解地區(qū)更改攔截器

2018-07-26 15:41 更新

You can enable changing of locales by adding the LocaleChangeInterceptor to one of the handler mappings (see [Section 21.4, "Handler mappings"](mvc.html

mvc-handlermapping "21.4 Handler mappings" )). It will detect a parameter in

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)用LocaleResolversetLocale()方法來更改地區(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>


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)