我正在尝试国际化并不断出现此错误:
The method getHeader(String) is undefined for the type HttpRequest
码:
List<Locale> LOCALES = Arrays.asList(new Locale("en"), new Locale("fr"));
public Locale resolveLocale(HttpRequest request) {
String headerLang = ((HttpRequest) request).getHeader("Accept-Language");
return headerLang == null || headerLang.isEmpty() ? Locale.getDefault()
: Locale.lookup(Locale.LanguageRange.parse(headerLang), LOCALES);
}
最佳答案
使用HttpServletRequest request
用HttpRequest request
更改HttpServletRequest request
码
public Locale resolveLocale(HttpServletRequest request) {
String headerLang = request.getHeader("Accept-Language");
return headerLang == null || headerLang.isEmpty() ? Locale.getDefault()
: Locale.lookup(Locale.LanguageRange.parse(headerLang), LOCALES);
}