//引入thymeleaf <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
login.button=登陆 login.password=密码 login.remember=记住我 login.tip=请登陆 login.username=用户名
login.button=Sign In login.password=PassWord login.remember=Remember Me login.tip=Please sign in login.username=UserName
login.button=登陆 login.password=密码 login.remember=记住我 login.tip=请登陆 login.username=用户名
** * Describe: 国际化 * Copyright: ITfxsen * Date: 2019/10/17 * Time: 16:18 * @author fu.qiang * @version 1.0 */ @Configuration public class MyLocaleResolver implements LocaleResolver { @Override public Locale resolveLocale(HttpServletRequest httpServletRequest) { String l = httpServletRequest.getParameter("l"); if (StringUtils.isEmpty(l)){ Locale locale = Locale.getDefault(); return locale; }else { String[] split = l.split("_"); return new Locale(split[0],split[1]); } }
/** * Describe: 注入自定义的LocaleResolver * @param * @return * @Time: 2019/10/18 9:38 * @autho: fu.qiang * @version 1.0 */ @Bean public LocaleResolver localeResolver(){ return new MyLocaleResolver(); }
<a class="btn btn-sm" th:href="@{/login(l='zh_CN')}">中文</a> <a class="btn btn-sm"th:href="@{/login(l='en_US')}"> English</a>