public class I18nInterceptor extends Object implements Interceptor
| 构造器和说明 |
|---|
I18nInterceptor() |
I18nInterceptor(String localePara,
String resName) |
I18nInterceptor(String localePara,
String resName,
boolean isSwitchView) |
| 限定符和类型 | 方法和说明 |
|---|---|
protected String |
getBaseName()
Return the baseName, which is used as base name of the i18n resource file.
|
protected String |
getLocalePara()
Return the localePara, which is used as para name to get locale from the request para and the
cookie.
|
protected String |
getResName()
Return the resName, which is used as attribute name to pass the Res object to the view.
|
void |
intercept(Invocation inv)
1: use the locale from request para if exists. change the locale write to the cookie 2: use
the locale from cookie para if exists. 3: use the default locale 4: use setAttr(resName,
resObject) pass Res object to the view.
|
void |
switchView(String locale,
Controller c)
在有些 web 系统中,页面需要国际化的文本过多,并且 css 以及 html 也因为际化而大不相同, 对于这种应用场景先直接制做多套同名称的国际化视图,并将这些视图以 locale
为子目录分类存放, 最后使用本拦截器根据 locale 动态切换视图,而不必对视图中的文本逐个进行国际化切换,省时省力。
|
protected String getLocalePara()
protected String getResName()
protected String getBaseName()
public void intercept(Invocation inv)
intercept 在接口中 Interceptorpublic void switchView(String locale, Controller c)
Copyright © 2015. All rights reserved.