springmvc的java配置类:
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/index.html","/");
}
}
实现页面重定向,当访问localhost:8080/index.html时跳转到localhost:8080/
<a class="btn btn-sm" th:href="@{/index.html(la='zh_CN')}">中文</a>
<a class="btn btn-sm" th:href="@{/index.html(la='en_US')}">English</a>
如上代码所示,链接的url配置了国际化参数la,但是通过点击"中文"(英文类似)链接会访问localhost:8080/index.html?la='zh_CN’并被自定义的java的springmvc配置类接收重定向到localhost:8080/中,此时参数不会一并传过去,在String language=httpServletRequest.getParameter(“la”);获取的参数值为null。需要直接访问才能获取到la的参数值,即html中的链接如下所示:
<a class="btn btn-sm" th:href="@{/(la='zh_CN')}">中文</a>
<a class="btn btn-sm" th:href="@{/(la='en_US')}">English</a>