C++ primer 第五版 Sales_item.h原始碼
阿新 • • 發佈:2020-12-26
技術標籤:道小雷spring boot
頁面國際化
package com.kuang.component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;
import javax.servlet. http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
//可以在連結上攜帶區域資訊
public class MyLocaleResolver implements LocaleResolver {
//解析請求
@Override
public Locale resolveLocale(HttpServletRequest request) {
String language = request.getParameter ("l");
Locale locale = Locale.getDefault(); // 如果沒有獲取到就使用系統預設的
//如果請求連結不為空
if (!StringUtils.isEmpty(language)){
//分割請求引數
String[] split = language.split("_");
//國家,地區
locale = new Locale(split[0],split[1]);
}
return locale;
}
@Override
public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {
}
}
- 擴充套件MVC類頁面配置元件
@Bean
public LocaleResolver localeResolver(){
return new MyLocaleResolver();
}