国际化基本配置
1、
spring.messages.basename=i18n/login
2、
3、国际化配置文件(根据链接上的区域信息)
public class myLoginLocaleResolver implements LocaleResolver {
@Override
public Locale resolveLocale(HttpServletRequest httpServletRequest) {
String l = httpServletRequest.getParameter("l");
Locale locale=Locale.getDefault();
if(l!=null) {
String[] s = l.split("_");
locale = new Locale(s[0], s[1]);
}
return locale;
}
@Override
public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {
}
}
4、
@Configuration
public class MyMvcConfiguration implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("login");
}
将配置添加到容器中
@Bean
public LocaleResolver localeResolver(){//这里这个localeResolver名字改了不能生效
return new myLoginLocaleResolver();
}
}